Word VBA / Macro problem with print & browser (Word 2000)

C

Chris

We are developing a Java application and using VB and VBA
code to perform a mail merge and then print. We are
successfully using a JSP to run a VB module which performs
a mail merge. We are trying to use VBA code to
automatically print the mail merge doc while it is
embedded in a browser window. We have macro code which
will print the document, but it will not shut down Word or
the IE window after it is printed. It appears to me that
once the Word VBA code to print is executed, the document
is no longer recognized as a Word doc, therefore any Word
VBA code set to run after the print statement will not
run. I know this is not the best print solution, but it
was what I have to work with. Here is the code which
generates a "4237 runtime error, command is not available"
after ActiveDocument.PrintOut when it tries to run
ActiveWindow.Close False:

Sub printclose()
Application.Visible = False
ActiveDocument.PrintOut
ActiveWindow.Close False
ActiveDocument.Close False
Application.OnTime _
when:=Now + TimeValue("00:0:15"), _
Name:="wantquit"
End Sub

Any ideas? I thought maybe I could work with the
InternetExplorer.Application object, but I need code to
recognize the existing object, can't get it to work with
CreateObject. By the way, I normally have this code in
the Auto_Open sub, I put it in a different sub for testing
purposes.

Thanks,
Chris
 
C

Cindy Meister -WordMVP-

Hi Chris,

My feeling is that the code is no longer regarding the same
document as being the "ActiveDocument". I'd try working with
an object variable that will clearly identify the document.
Roughly:

Dim doc as Word.Document
set doc = ActiveDocument
doc.PrintOut
'note: make sure PrintBackground is False
doc.Close false
Here is the code which
generates a "4237 runtime error, command is not available"
after ActiveDocument.PrintOut when it tries to run
ActiveWindow.Close False:

Sub printclose()
Application.Visible = False
ActiveDocument.PrintOut
ActiveWindow.Close False
ActiveDocument.Close False
Application.OnTime _
when:=Now + TimeValue("00:0:15"), _
Name:="wantquit"
End Sub

Any ideas?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan
24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
C

Chris

Cindy,
I have tried your suggestion and it did not work. I have
also tried similar things like:
Sub AutoOpen()
MyWord.Visible = False
MyWord.ActiveDocument.PrintOut
MyWord.ActiveDocument.Close False
End Sub
or:
Sub AutoOpen()
With ActiveDocument
.PrintOut Background:=False
.Close savechanges:=False
.Parent.Quit
End With
End Sub
or:
Sub AutoOpen()
Dim MyWord As Object
Set MyWord = GetObject(, "Word.Application")
Dim IE As Object
Dim IEDoc As Object
Set IE = GetObject(, "InternetExplorer.Application")
Set IEDoc = MyWord.ActiveDocument
IEDoc.PrintOut
IEDoc.Close
IE.Quit
End Sub

Thanks,
Chris
 

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