Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default How do you change the default printer?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default How do you change the default printer?

"DennisE" wrote...
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?


You can use VBA to change the name of the ActivePrinter. The macro recorder
gives something like

Application.ActivePrinter = "Generic / Text Only on FILE:"

You could always put this in a BeforePrint event handler.

The default printer, on the other hand, is a Windows-wide configuration
setting. You may need to make a Windows API call to do this.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you change the default printer?

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you change the default printer?

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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default settings for my printer in Excel change when Import workbo rickitoni Excel Discussion (Misc queries) 1 February 7th 09 06:46 PM
Default Printer aftamath77 Excel Discussion (Misc queries) 2 November 26th 08 05:37 PM
members on my network printer not able to print to default printer smeheut Excel Discussion (Misc queries) 0 June 18th 07 06:42 PM
How do I change default printer settings Vanessa Setting up and Configuration of Excel 2 September 3rd 06 12:16 AM
excel macro to automatically change default printer James Bromley Excel Discussion (Misc queries) 1 January 15th 06 11:42 AM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"