A
Axel Dahmen
Hi,
I'm developing a VB6 project where I want to add a table with content to an
existing Word document. Somehow the code I'm writing doesn't work. The error
message I get is not very targeting (see below). Can someone please help me
out here?
This is my code (I'm referencing "Microsoft Word 9.0 Object Library"):
---------------------------------------------------------
Sub Main()
Dim wrd As Document
Dim ta As Table
Set wrd = GetObject("C:\Temp\Dok1.doc")
With wrd
Set ta = .Tables.Add(.Range(.Content.End - 1, .Content.End), _
2, 3, wdWord9TableBehavior, wdAutoFitContent)
ta.Cell(1, 1).Range.Text = "Hello" ' This yields the exception below
.Save
.Application.Quit wdDoNotSaveChanges ' Strange: Word doesn't quit.
' It's still in Task Manager
End With
End Sub
---------------------------------------------------------
I get the following error message when executing ta.Cell(1, 1).Range.Text =
"Hello":
Run time error -2147417851 (80010105) method 'Text' of object 'Range'
failed.
Moreover, if I skip the line in debugger after exception, save is performed
and changes ARE applied. Last but not least ".Application.Quit" does NOT
quit Word. It's still visible in Task Manager.
Any help is quite appreciated.
TIA,
Axel Dahmen
I'm developing a VB6 project where I want to add a table with content to an
existing Word document. Somehow the code I'm writing doesn't work. The error
message I get is not very targeting (see below). Can someone please help me
out here?
This is my code (I'm referencing "Microsoft Word 9.0 Object Library"):
---------------------------------------------------------
Sub Main()
Dim wrd As Document
Dim ta As Table
Set wrd = GetObject("C:\Temp\Dok1.doc")
With wrd
Set ta = .Tables.Add(.Range(.Content.End - 1, .Content.End), _
2, 3, wdWord9TableBehavior, wdAutoFitContent)
ta.Cell(1, 1).Range.Text = "Hello" ' This yields the exception below
.Save
.Application.Quit wdDoNotSaveChanges ' Strange: Word doesn't quit.
' It's still in Task Manager
End With
End Sub
---------------------------------------------------------
I get the following error message when executing ta.Cell(1, 1).Range.Text =
"Hello":
Run time error -2147417851 (80010105) method 'Text' of object 'Range'
failed.
Moreover, if I skip the line in debugger after exception, save is performed
and changes ARE applied. Last but not least ".Application.Quit" does NOT
quit Word. It's still visible in Task Manager.
Any help is quite appreciated.
TIA,
Axel Dahmen