Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert to tables in a word doc from vbscript.

Status
Not open for further replies.

diembi

Programmer
Sep 22, 2001
238
ES
Hello!!!!
How I can create two tables in a word document from vbscript?
I set two tables in the document but the second table is writed in the first cell of the first cell and i want write the second table after the first table. This is the vbscript code i use:

Set tabla_1 = oDoc.Tables.Add(oDoc.Range(0,0), 5, 5)
Set tabla_2 = oDoc.Tables.Add(oDoc.Range(0,0), 5, 5)

Thanks!!
 
Hello, danielmontejo.

Here is some measure you should have somehow, one form or another.

Option Explicit

Dim oWD, oSelection, oDoc, oTable_1, oTable_2

Set oWD = CreateObject("Word.Application")
oWD.Visible = True
Set oDoc = oWD.Documents.Add
Set oSelection = oWD.Selection

oSelection.Range.Start = 0
oSelection.Range.End = 0
Set oTable_1 = oDoc.Tables.Add(oSelection.Range,5,5)

oSelection.WholeStory
oSelection.EndKey
oSelection.TypeParagraph

oSelection.Range.Start = 0
oSelection.Range.End = 0
Set oTable_2 = oDoc.Tables.Add(oSelection.Range,5,5)

You do not have to follow to the letter. It is just for illustrative purpose. It depends on what else you have on the document. But you get the idea. Make good use of Selection. And it is not real fun most of the time.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top