Mr Doubtfire
10-09-2005, 03:55 PM
I have tried a simple testing to create to two different tables with different column settings. BUT only to find the second one appears. Please help and code is as followed.: pray2:
Public objApp As Word.Application
Public Tbl1 As Table
Public Tbl2 As Table
Private Sub Command1_Click()
On Error Resume Next
Set objApp = GetObject(, "Word.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Word.Application")
End If
objApp.Documents.Open FileName:="c:\test\temp1.dot"
Set Tbl1 = objApp.ActiveDocument.Tables.Add _
(Range:=objApp.Selection.Range, _
NumRows:=2, NumColumns:=2)
Tbl1.Columns(1).Width = 100
Tbl1.Columns(2).Width = 100
Tbl1.Cell(1, 1).Range.Text = "Table1 - col1"
Tbl1.Cell(1, 2).Range.Text = "Table1 - col2"
Tbl1.Cell(2, 1).Range.Text = "VBA 1"
Tbl1.Cell(2, 2).Range.Text = "50%"
Set Tbl1 = Nothing
objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 _
'<- move to end of table
objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove _
'<- move foward 1 line
Set Tbl2 = objApp.ActiveDocument.Tables.Add _
(Range:=objApp.Selection.Range, _
NumRows:=2, NumColumns:=2)
Tbl2.Columns(1).Width = 100
Tbl2.Columns(2).Width = 100
Tbl2.Cell(1, 1).Range.Text = "Table2 - col1"
Tbl2.Cell(1, 2).Range.Text = "Table2 - col2"
Tbl2.Cell(2, 1).Range.Text = "VBA 2"
Tbl2.Cell(2, 2).Range.Text = "100%"
Set Tbl2 = Nothing
objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 _
'<- move to end of table
objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove _
'<- move foward 1 line
objApp.ActiveDocument.SaveAs FileName:="c:\test\test1.doc"
objApp.Quit False
Set objApp = Nothing
MsgBox "done"
End Sub
Public objApp As Word.Application
Public Tbl1 As Table
Public Tbl2 As Table
Private Sub Command1_Click()
On Error Resume Next
Set objApp = GetObject(, "Word.Application")
If objApp Is Nothing Then
Set objApp = CreateObject("Word.Application")
End If
objApp.Documents.Open FileName:="c:\test\temp1.dot"
Set Tbl1 = objApp.ActiveDocument.Tables.Add _
(Range:=objApp.Selection.Range, _
NumRows:=2, NumColumns:=2)
Tbl1.Columns(1).Width = 100
Tbl1.Columns(2).Width = 100
Tbl1.Cell(1, 1).Range.Text = "Table1 - col1"
Tbl1.Cell(1, 2).Range.Text = "Table1 - col2"
Tbl1.Cell(2, 1).Range.Text = "VBA 1"
Tbl1.Cell(2, 2).Range.Text = "50%"
Set Tbl1 = Nothing
objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 _
'<- move to end of table
objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove _
'<- move foward 1 line
Set Tbl2 = objApp.ActiveDocument.Tables.Add _
(Range:=objApp.Selection.Range, _
NumRows:=2, NumColumns:=2)
Tbl2.Columns(1).Width = 100
Tbl2.Columns(2).Width = 100
Tbl2.Cell(1, 1).Range.Text = "Table2 - col1"
Tbl2.Cell(1, 2).Range.Text = "Table2 - col2"
Tbl2.Cell(2, 1).Range.Text = "VBA 2"
Tbl2.Cell(2, 2).Range.Text = "100%"
Set Tbl2 = Nothing
objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 _
'<- move to end of table
objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove _
'<- move foward 1 line
objApp.ActiveDocument.SaveAs FileName:="c:\test\test1.doc"
objApp.Quit False
Set objApp = Nothing
MsgBox "done"
End Sub