Scorpio Posted March 15, 2005 Posted March 15, 2005 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 doesn't 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 Quote
SonicBoomAu Posted March 15, 2005 Posted March 15, 2005 You could try to use the "odoc.quit()" instead of "odoc.APPLICATION.QUIT(0)", and you could set "odoc = nothing" & "oword = nothing" Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
herilane Posted March 17, 2005 Posted March 17, 2005 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 wasn't running) then use CreateObject. Using odoc.Quit is unlikely to work, since the Word.Document object does not have a Quit method. :) It'll have to be oword.Quit or odoc.Application.Quit. Quote
SonicBoomAu Posted March 17, 2005 Posted March 17, 2005 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. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
SonicBoomAu Posted March 17, 2005 Posted March 17, 2005 You might also want to have a look at the following thread. http://www.xtremedotnettalk.com/showthread.php?t=91634 It will give you some examples of how to open a new instance of Word. Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
Recommended Posts