this shows how to use the Windows API in
VB to do it. It would need to be
adapted to VBA.
http://support.microsoft.com/default...b;en-us;266767
HOWTO: Set Which Printer Is the System Default Printer
Another approach might be to take a picture of the useform, put it on a
blank sheet and print the sheet.
Following code was posted previously by Orlando Magalhaes Filho:
In a general module put in these declarations/code:
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_SNAPSHOT = &H2C
Sub Test()
UserForm1.Show
End Sub
In the code module of the Userform:
Private Sub CommandButton1_Click()
keybd_event VK_SNAPSHOT, 0, 0, 0
Workbooks.Add
Application.Wait Now + TimeValue("00:00:01")
ActiveSheet.PasteSpecial Format:="Bitmap", Link:=False, _
DisplayAsIcon:=False
ActiveSheet.Range("A1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWorkbook.Close False
End Sub
This takes a "picture" of the userform and pastes it on a sheet (adds a
workbook with a sheet, prints, then closes the workbook without saving
change). It then prints the picture on the sheet.
Regards,
Tom Ogilvy
Tom Ogilvy wrote in message
...
I assume you mean for Excel and not for all windows applications.
Look at help setting the ActivePrinter
(turn on the macro recorder and perform the action manually - that will
also
be helpful).
I believe that and what you have shown are what are offered internally to
Excel and VBA. After that, you would probably need to use the Windows
API.
--
Regards,
Tom Ogilvy
DennisE wrote in message
...
I would like to from within Excel as an VBA instruction change the
name of the default printer, just as if I went to the Windows Control
Panel and did it. Incorporating in my code either of the instructions
Application.Dialogs(xlDialogPrint).Show or
Application.Dialogs(xlDialogPrinterSetup).Show
lets me change the printer for that job, but seems to leave the
name of the default printer the same as before. Any suggestions,
anyone?
-- Dennis Eisen