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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add table to a word doc

Status
Not open for further replies.

joecrazy

Technical User
Aug 4, 2005
3
US
hi,

i try to add tables to a word doc, the problem is, the next table is always add befor the last one

looks like this:

Do While textfile.AtEndOfStream <> True
txt = textfile.ReadLine
a = Split(txt,vbTab)

If a(1)= "@@" Then
i=1
j=j+1
objDoc.Tables.Add objRange,1,5
'here i tried to count the tables by another var, but doesn't work e.g.:Set objTable = objDoc.Tables(j)
Set objTable = objDoc.Tables(1)
objTable.Range.Font.Size = 10

'objTable.AutoFitBehavior(0)
objTable.Columns(1).PreferredWidth = 150
objTable.Columns(2).PreferredWidth = 200
objTable.Columns(3).PreferredWidth = 60
objTable.Columns(4).PreferredWidth = 60
objTable.Columns(5).PreferredWidth = 250

'Add Headline with special formatting
objTable.Rows.Add()
objTable.Rows(i).HeadingFormat=True
objTable.Rows(i).HeadingFormat=1
objTable.Rows(i).Range.Font.Size = 16
objTable.Cell(i, 1).Range.Text = a(0)
objTable.Rows(i).Range.Font.Bold = False
objTable.Rows(i).Cells.Merge

'add column headline for each table
i=i+1
objTable.Rows.Add()
objTable.Rows(i).HeadingFormat=True
objTable.Rows(i).HeadingFormat=1
objTable.Rows(i).Range.Font.Size = 14
objTable.Rows(i).Range.Font.Bold = False
objTable.Cell(i, 1).Range.Text = "ELEMENT"
objTable.Cell(i, 2).Range.text = "LABEL"
objTable.Cell(i, 3).Range.text = "USER"
objTable.Cell(i, 4).Range.text = "DATE"
objTable.Cell(i, 5).Range.text = "COMMENT"
'objRange.ParagraphFormat.Alignment = 0
i=i+1
Else
objDoc.Tables(1).Rows.Add()
objTable.Rows(i).AllowBreakAcrossPages = False
objRange.ParagraphFormat.Alignment = 0
objTable.Rows(i).Range.Font.Bold = False
objTable.Cell(i, 1).Range.Text = a(0)
objTable.Cell(i, 2).Range.text = a(1)
objTable.Cell(i, 3).Range.text = a(2)
objTable.Cell(i, 4).Range.text = a(3)
objTable.Cell(i, 5).Range.text = a(4)
i=i+1
End If
Loop
 
The best way to figure this out is to use the Macro Recorder. Use it to manually do the additions once, then edit the macro code to see how/were it did the changes.

I hope you find this post helpful.

Regards,

Mark
 
does the macro recorder also work with vbs, i had big problems to convert code from vba to vbs, there are still a lot of differnces
 
I've never had a real problem wih converting recorded vba to vbs, but if you do then post the vba here and I'm sure someone can help.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
With past versions there certainly were problems, but if you are using Word XP or Word 2003 then you shoud not have a problem.

I hope you find this post helpful.

Regards,

Mark
 
i use word 2000, this could be the prob, but the problem is solved, thanks

i use a word doc now ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top