Word Crashes intermittently

R

Ravi Chand

Hi

My code adds a new document (word 2003) 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.
 
B

Beth Melton

Hi Ravi,

I don't see anything in your code that stands out but I would still
post in one of the VBA ngs. One of the gurus there may spot something
or have an idea. Sorry!

--
Please post all follow-up questions to the newsgroup. Requests for
assistance by email can not be acknowledged.

~~~~~~~~~~~~~~~
Beth Melton
Microsoft Office MVP

Word FAQ: http://mvps.org/word
TechTrax eZine: http://mousetrax.com/techtrax/
MVP FAQ site: http://mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top