Write Word Table in Visual Basic
Hi
I am writing to a Word document from Visual Basic
It tried this code:
Set wrd = Word.Documents.Open("C:\test.doc")
Selection.InsertAfter Text:="Table to come"
Selection.Font.Bold = True
wrd.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:=2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
wrd.Tables(1).Rows(1).Select
wrd.Tables(1).Cell(1, 2).Select
wrd.Save
The codes works but table is overwriting the text
How can i say
"Table to come" and then table?
Thanks
Re: Write Word Table in Visual Basic
VB Code:
Selection.Font.Bold = True
Selection.EndKey Unit:=wdLine ' add this line
should work
pete
Re: Write Word Table in Visual Basic
while the above code worked, probably
VB Code:
Selection.Collapse Direction:=wdCollapseEnd
is more correct to use
pete
Re: Write Word Table in Visual Basic
All you need is to write the "Table coming soon text" and then a couple of line breaks and then your .Add table code line.
VB Code:
Selection.InsertAfter Text:="Table to come"
Selection.Font.Bold = True
Selection.TypeParagraph
wrd.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns ......