S
Sam
Hi,
I am trying to create a word document programatically in vb.net 2003.The
program would create a blank word document, insert a table and populate it
with some values.
my program does successfully create the word document, inserts table and
populates it.The probelm I am running into is that just before the program
ends I get the following error message:
Application Error: The instruction at "0x5b261e4e" referenced memory at
"0x0454e2c8". The memory could not be "read" Click on OK to terminate the
program.
I dont get this error message if I insert sentences instead of table.
Here's the code snippet that inserts table:
With currentSelection
Dim sTableRng As Word.Range = sWord.Selection.Range
sDoc.Tables.Add(sTableRng, sRowCount, sColCount)
'Add table row headings
With sDoc.Tables.Item(1)
'Format the headings
.Cell(1, 1).Range.Font.Bold = True
.Cell(1, 2).Range.Font.Bold = True
.Cell(1, 3).Range.Font.Bold = True
'Enter heading names
.Cell(1, 1).Range.Text = "Item Name"
.Cell(1, 2).Range.Text = "Type"
.Cell(1, 3).Range.Text = "Width"
End With
'Add values into the table
'Declare variable to iterate through rows of table
Dim sTI As Integer
'Enter field values
For sTI = 2 To sRowCount + 1
With sDoc.Tables.Item(1)
'Format the headings
.Cell(sTI, 1).Range.Font.Bold = False
.Cell(sTI, 2).Range.Font.Bold = False
.Cell(sTI, 3).Range.Font.Bold = False
'Enter heading names
.Cell(sTI, 1).Range.Text = "Item1"
.Cell(sTI, 2).Range.Text = "Type1"
.Cell(sTI, 3).Range.Text = "Width1"
End With
Next
sTableRng = Nothing
End With
I tried the releaseCOMobject method at the end to close any open
connections, but that did not help either.
Any help is greatly appreciated.
Thanks
Sam
I am trying to create a word document programatically in vb.net 2003.The
program would create a blank word document, insert a table and populate it
with some values.
my program does successfully create the word document, inserts table and
populates it.The probelm I am running into is that just before the program
ends I get the following error message:
Application Error: The instruction at "0x5b261e4e" referenced memory at
"0x0454e2c8". The memory could not be "read" Click on OK to terminate the
program.
I dont get this error message if I insert sentences instead of table.
Here's the code snippet that inserts table:
With currentSelection
Dim sTableRng As Word.Range = sWord.Selection.Range
sDoc.Tables.Add(sTableRng, sRowCount, sColCount)
'Add table row headings
With sDoc.Tables.Item(1)
'Format the headings
.Cell(1, 1).Range.Font.Bold = True
.Cell(1, 2).Range.Font.Bold = True
.Cell(1, 3).Range.Font.Bold = True
'Enter heading names
.Cell(1, 1).Range.Text = "Item Name"
.Cell(1, 2).Range.Text = "Type"
.Cell(1, 3).Range.Text = "Width"
End With
'Add values into the table
'Declare variable to iterate through rows of table
Dim sTI As Integer
'Enter field values
For sTI = 2 To sRowCount + 1
With sDoc.Tables.Item(1)
'Format the headings
.Cell(sTI, 1).Range.Font.Bold = False
.Cell(sTI, 2).Range.Font.Bold = False
.Cell(sTI, 3).Range.Font.Bold = False
'Enter heading names
.Cell(sTI, 1).Range.Text = "Item1"
.Cell(sTI, 2).Range.Text = "Type1"
.Cell(sTI, 3).Range.Text = "Width1"
End With
Next
sTableRng = Nothing
End With
I tried the releaseCOMobject method at the end to close any open
connections, but that did not help either.
Any help is greatly appreciated.
Thanks
Sam