|
-
Oct 22nd, 2002, 08:41 PM
#1
Thread Starter
New Member
Problem inserting table to ms word using vb
Anybody noe how to insert data into ms word table?
thanks
-
Oct 22nd, 2002, 09:18 PM
#2
Fanatic Member
Re: Problem inserting table to ms word using vb
Originally posted by knic
Anybody noe how to insert data into ms word table?
thanks
YEP!
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
-
Oct 22nd, 2002, 09:21 PM
#3
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."
-
Oct 22nd, 2002, 09:22 PM
#4
Don't forget to add the reference to Word and set your word object.
-
Oct 22nd, 2002, 09:29 PM
#5
Fanatic Member
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.
-
Oct 23rd, 2002, 02:44 AM
#6
Lively Member
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
-
Oct 23rd, 2002, 10:15 PM
#7
Thread Starter
New Member
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
-
Oct 23rd, 2002, 10:31 PM
#8
Try this...
Code:
Application.Selection.InlineShapes.AddPicture "D:\My Documents\03Cobra.jpg", False, True
-
Oct 24th, 2002, 12:50 AM
#9
Thread Starter
New Member
thanks
now i can add the picture
but how to adjust the size of the pic?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|