R
Ravi Chand
Hi
My code adds a new document at run time and then pastes some stuff on
it. After manipulating this data it fetches it and inserts it in a
different word document. The problem is, intermittently word is
crashing with this code. It doesn't happen everytime and on every
machine.
The code looks something like this...
'Create a new document object
Dim objWdDoc As Document
Set objWdDoc = objWord.Documents.Add(, , , False)
'Paste the content of the clipboard in the new document
objWdDoc.Content.Paste
'Format the tables
For tableCount = 1 To objWdDoc.Tables.Count
objWdDoc.Tables(tableCount).Rows.LeftIndent = 0
objWdDoc.Tables(tableCount).Rows.Alignment = wdAlignRowLeft
objWdDoc.Tables(tableCount).Range.Font.Name = "Reuters Mono"
objWdDoc.Tables(tableCount).Range.Font.Size = 10
objWdDoc.Tables(tableCount).Range.Font.Color = wdColorBlack
objWdDoc.Tables(tableCount).Range.Font.Bold = 0
objWdDoc.Tables(tableCount).Range.Font.Underline =
wdUnderlineNone
objWdDoc.Tables(tableCount).Range.Font.Italic = 0
Next
'Extract the formatted data
Dim wrdXML As String
wrdXML = objWdDoc.Content.Xml
objWdDoc.Close (False)
Set objWdDoc = Nothing
'Insert the data in the original document...
objWord.ScreenUpdating = False
objWord.Selection.InsertXML wrdXML
objWord.ScreenUpdating = True
The problem is, intermittently word is crashing with this code. It
doesn't happen everytime and on every machine.
Any help would be appreciated.
Thanks and Regards
Ravi Chand.
My code adds a new document at run time and then pastes some stuff on
it. After manipulating this data it fetches it and inserts it in a
different word document. The problem is, intermittently word is
crashing with this code. It doesn't happen everytime and on every
machine.
The code looks something like this...
'Create a new document object
Dim objWdDoc As Document
Set objWdDoc = objWord.Documents.Add(, , , False)
'Paste the content of the clipboard in the new document
objWdDoc.Content.Paste
'Format the tables
For tableCount = 1 To objWdDoc.Tables.Count
objWdDoc.Tables(tableCount).Rows.LeftIndent = 0
objWdDoc.Tables(tableCount).Rows.Alignment = wdAlignRowLeft
objWdDoc.Tables(tableCount).Range.Font.Name = "Reuters Mono"
objWdDoc.Tables(tableCount).Range.Font.Size = 10
objWdDoc.Tables(tableCount).Range.Font.Color = wdColorBlack
objWdDoc.Tables(tableCount).Range.Font.Bold = 0
objWdDoc.Tables(tableCount).Range.Font.Underline =
wdUnderlineNone
objWdDoc.Tables(tableCount).Range.Font.Italic = 0
Next
'Extract the formatted data
Dim wrdXML As String
wrdXML = objWdDoc.Content.Xml
objWdDoc.Close (False)
Set objWdDoc = Nothing
'Insert the data in the original document...
objWord.ScreenUpdating = False
objWord.Selection.InsertXML wrdXML
objWord.ScreenUpdating = True
The problem is, intermittently word is crashing with this code. It
doesn't happen everytime and on every machine.
Any help would be appreciated.
Thanks and Regards
Ravi Chand.