Problems with Office 2003

Scorpio

Member
Joined
Sep 11, 2003
Messages
8
Here is the code i use to print a document using Word
Basically i open a ".dot" document, fill the bookmark, print the document then quit without
saving it


Dim oword As Object
Dim odoc As Object
Dim file As String

File="c:\test.dot"
oword = CreateObject("Word.Application")
oword.visible = False
Try
odoc = oword.documents.open(file)
Catch ex As Exception
MsgBox("Cannot find the template " & file & ". Operation cancelled")
oword.quit(0)
Exit Sub
End Try

odoc.bookmarks("Title").RANGE.TEXT = Title
odoc.bookmarks("SubTitle").RANGE.TEXT = SubTitle
odoc.printout(0)
odoc.APPLICATION.QUIT(0)

It works fine with office 2002
But when the programs runs with office 2003, i have some problems
If outlook 2003 is currently running on the machine, closing the word document doesnt work and hangs
with the following message

"Word cannot save this file because it is already open elsewhere
(C:Documents and Settings\...\Normal.dot)"
And the user has to click on button OK to close the word window
If Outlook 2003 is not running on the machine (just installed), everythings works fine

Any solution to this problem (except asking user to close Outlook before printing) ?

(PS : users have the option "use Word as email editor" selected
 
You could try to use the "odoc.quit()" instead of "odoc.APPLICATION.QUIT(0)", and you could set "odoc = nothing" & "oword = nothing"
 
If Outlook is set to use Word as the e-mail editor, Outlook starts up a hidden instance of Word.

Since Word is then already running, you could try and reuse that existing instance. Use GetObject instead of CreateObject. If GetObject fails (i.e. Word wasnt running) then use CreateObject.

Using odoc.Quit is unlikely to work, since the Word.Document object does not have a Quit method. :) Itll have to be oword.Quit or odoc.Application.Quit.
 
Why not create a new instance of the word object.
Dim oword As New Word.application

That way you would only be closing this instance of Word.
 
Back
Top