Anybody noe how to insert data into ms word table?
thanks
Printable View
Anybody noe how to insert data into ms word table?
thanks
YEP! :DQuote:
Originally posted by knic
Anybody noe how to insert data into ms word table?
thanks
Word VBA help has lots of info on this topic. In MS Word press Alt + F11 (which will open the VBA editor). Then click help and search these topics:
Recording a macro to generate code
Working with tables
InsertDatabase Method
:)
If its a table that your creating on the fly, then just move to the cell you want by doing like this...
Move up 2 rows.
Application.Selection.MoveUp wdLine, 2
Application.Selection.TypeText "This goes in the table cell."
Change the column...
Application.Selection.MoveRight wdCell, 1
If your opening a previously created document then...
Move down to the correct position and do the same...
Application.Selection.MoveDown wdLine, 8
Application.Selection.TypeText "This goes in the table cell."
:cool:
Don't forget to add the reference to Word and set your word object.
Or....you can take a few minutes to read up on the Working with tables help topic and learn how to deal directly with cells and ranges without the jittering, time-consuming, Selection.Move methods. ;)
Not sure if you want to create the table youself, this is a section of some code I used to do this from a sql server.
Dont forget the ref to word though
VB Code:
Set t = objdoc.Range(match.FirstIndex, match.FirstIndex + match.Length) Dim myTable As Word.Table Set myTable = objdoc.Tables.Add(t, Rows, cols) With myTable For y = 1 To cols .Cell(1, y).Range.InsertAfter notNull(rs.Fields(y - 1).Name) Next y For x = 2 To Rows For y = 1 To cols .Cell(x, y).Range.InsertAfter notNull(rs(y - 1)) Next y rs.MoveNext Next x .Columns.AutoFit .AutoFormat wdTableFormatProfessional .Select End With
thanks
i have learnt how to add the table now
but i have a problem again
how to add a image at the top of the document
because i need to generate a report from the ms word
so i need to insert a company logo there
Try this...
Code:Application.Selection.InlineShapes.AddPicture "D:\My Documents\03Cobra.jpg", False, True
thanks
now i can add the picture
but how to adjust the size of the pic?