Reset printer to default using VBA (Word 2000)

The situation: A user has printed something to a printer (I'll call it Print2) *other* than their default printer (Print1). Word retains the Print2 as the active printer until the user switches back.

I need to create a button that will set the active printer back to the default printer. The default printer is not the same for all users, I can't hardcode that--I essentially need something that sets the active printer to the default printer.

Why can't users just change this themselves? I do not know. Apparently they are too well paid to be expected to understand how to check their printer settings. (Grr. Sorry. Just venting.)

Re: Reset printer to default using VBA (Word 2000)

I had a similar problem in a project that I am developing - I needed to switch to a different printer before opening Crystal reports (which picks up the default printer and doesn't let you change before printing!).

Couple of functions here might help...

' // To notify applications the printer has changed
Private Const HWND_BROADCAST As Long = &HFFFF
Private Const WM_WININICHANGE As Long = &H1A

Re: Reset printer to default using VBA (Word 2000)

<P ID="edit" class=small>Edited by klyjen on 20-Dec-01 13:28.</P>Dylan--that did it! Thanks! I used your code, and then added a "ReSetDefaultMacro sub that looks like this...I had to do that because these are network printers and returning the string as your function returned it couldn't be read by the application.activeprinter setting.

'runs the GetDefaultPrinter function (above) and returns the value
'into a string called sDefaultPrinter--this returns a string that
'looks like (DC-7B1,winspool,NE74 <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
sDefaultPrinter = GetDefaultPrinter()
'clears the active printer
Application.ActivePrinter = ""
'determines the position of the first comma in the string
First = InStr(1, sDefaultPrinter, ",")
'determines the position of the last comma in the string
Last = InStrRev(sDefaultPrinter, ",")
'determines the total length of the string
Total = Len(sDefaultPrinter)
'determines the printer name (the characters up to the first
'comma in the string)
PrinterName = Left(sDefaultPrinter, First - 1)
'determines the code at the end of the string)
PrinterEnd = Right(sDefaultPrinter, Total - Last)
'resets the active printer to the default, setting the string to
'look like it should (i.e., "DC-7B1 on NE74:")
Application.ActivePrinter = PrinterName & " on " & PrinterEnd
'creates a message box letting the user know the printer has
'been reset and what its value is now
response = MsgBox(("Your printer has been reset to " & PrinterName & "."), vbOKOnly)

End Sub

Thanks very much for your help. I will definitely keep your code for future use!

Jen

EDIT: That shouldn't be a smiley, it should be a : followed by a ) I can't figure out how to turn off the smileys in here!