update template with macro then print gives winword.exe error

G

gary at protocol

Run a template with a macro, then tried to print and every once in a while
gives the following error:
App Name winword.exe
App Ver 10.0.6612.0
Mod Name winword.exe
Offset 00010e58

Using Word 2002 SP3
any help would be appreciated.
Gary
 
G

gary at protocol

Here is the code it is running:
Sub PrintDoc()
On Error GoTo errorhandler


ActivePrinter = "\\ntserver\document"
Options.DefaultTray = "Upper Paper tray"
ActiveDocument.PrintOut

Exit Sub

errorhandler:
MsgBox ("Printer Error document didn't Print")
Exit Sub

End Sub

Thanks
Gary
 
B

Beth Melton

I don't necessarily see anything wrong with the code but I wonder if
it has anything to do with changing the default printer for Windows
instead of changing the printer just for Word.

Take a look at this article for the code you need to use to change the
printer just for Word:
http://word.mvps.org/FAQs/MacrosVBA/ChangeCurPrinter.htm

I'm also wondering if printer driver is a network printer driver,
rather than a local printer driver, and the reason you encounter the
error is because the network is unavailable (this can happen if you
have the workstation set to AutoDisconnect). If Word queries the
printer driver and it is unavailable then Word can crash. If you
think this is the issue then remove the printer and add it back using
the Add Printer Wizard so a local printer driver will be installed.

btw, the parenthesis around your MsgBox arguments are unnecessary and
really should only be used if you are passing the value of the button
that is clicked to a variable such as:

intResponse=MsgBox("Message prompt", vbYesNo + vbQuestion)

If intResponse=vbYes then
'Code

Actually for your error handler I recommend using something like:

MsgBox Err.Number & " - " & Err.Description

That way if you do encounter an error you don't end up getting a
generic error message. Instead the message may held shed some light on
why the error has occurred.

Consider a generic message such as "winword.exe has encountered an
error" vs. "The network printer is not available". ;-)

--
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