TeDeSm
asked on
How to create a Word document using current Word instance, then close it.
I have a project that creates a number of Word documents, one after the other. The first one document is to open Word and the remainder will use the same Word instance. After each document is created, it is to be printed then closed before another document is created.
How would I handle the Word application when creating the documents and then disposing of the document object without any 'save to normal.dot' dialogues?
How would I handle the Word application when creating the documents and then disposing of the document object without any 'save to normal.dot' dialogues?
You should be able to close each document with the parameter wdDoNotSave. If that gives you trouble, try setting the Saved property of the document to True, then closing it.
You should just go into Word and tell it not to prompt you to save normal.dot.
Tools, Options, Save... uncheck "Prompt to save change to normal"
Tools, Options, Save... uncheck "Prompt to save change to normal"
>without any 'save to normal.dot' dialogues?
Is that all you need help with?
Is that all you need help with?
ASKER
The option to not save to normal.dotm is unchecked.
However, I think the problem I had is with the code that creates the documents. I have amended it to include a Try/Catch as below. However I have made an assumption that the only exception thrown would be if Word was already open. In VBA a specific error 429 would be thrown.
However, I think the problem I had is with the code that creates the documents. I have amended it to include a Try/Catch as below. However I have made an assumption that the only exception thrown would be if Word was already open. In VBA a specific error 429 would be thrown.
Try
oWord = GetObject(, "Word.Application")
Catch ex As Exception
' Word is not already open, create new Word object
oWord = CreateObject("Word.Application")
Err.Clear()
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Still had to use Try/Catch to handle when Word was not open, however it does give an exception code.
Try
oWord = System.Runtime.InteropServ ices.Marsh al.GetActi veObject(" Word.Appli cation")
Catch
oWord = New Word.Application
End Try
Try
oWord = System.Runtime.InteropServ
Catch
oWord = New Word.Application
End Try