Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Junior Member
 
Posts: 13
Default VBA API Default printer

Hi,

I have an issue with some code I'm trying to produce. Though at the
moment I feel like i wish i hadn't started! :P


I am producing a batch printing script for some drawing register
spreadsheets I have. Basically I need to be able to set the default
printer in WINDOWS from within VBA to different printers (printers
setup with the default print settings to different page sizes)
depending upon wether a certain cell contains the text A4-A3-A2-A1 or
A0.


These will be controling External documents from PDF's to AutoCAD
drawings and therefore this needs to be using the windows default
printer to print via the ShellExecute() and not the activeprinter
internal command.


I've looked around and found some VB script that look like it works
(but would need tweaking, but I just can't make any headway with
getting it to work in VB.


http://support.microsoft.com/default...b;en-us;266767


Can anyone help me? This is the final stage of this project thats
taken me a while! :) I'd appreciate any pointers at all :)


Dave
PS this has been posted elsewhere i'm just getting desperate :P lol

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default VBA API Default printer

"ArmsteR" wrote:

Hi,

I have an issue with some code I'm trying to produce. Though at the
moment I feel like i wish i hadn't started! :P


I am producing a batch printing script for some drawing register
spreadsheets I have. Basically I need to be able to set the default
printer in WINDOWS from within VBA to different printers (printers
setup with the default print settings to different page sizes)
depending upon wether a certain cell contains the text A4-A3-A2-A1 or
A0.


These will be controling External documents from PDF's to AutoCAD
drawings and therefore this needs to be using the windows default
printer to print via the ShellExecute() and not the activeprinter
internal command.


I've looked around and found some VB script that look like it works
(but would need tweaking, but I just can't make any headway with
getting it to work in VB.


http://support.microsoft.com/default...b;en-us;266767


Can anyone help me? This is the final stage of this project thats
taken me a while! :) I'd appreciate any pointers at all :)



You can try this code, it uses WMI Win32_Printer class:



Sub SetDefaultPrinter()

'get printer name

strPrinterName = Cells(1, 1)

'connect to WMI locally

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& "root\cimv2")

'get WMI printer object

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = '" _
& strPrinterName & "'")

'try setting the default printer and report the result

If colInstalledPrinters.Count = 1 Then

For Each objPrinter In colInstalledPrinters
retVal = objPrinter.SetDefaultPrinter()
Next

If retVal = 0 Then
MsgBox "default printer is " & strPrinterName
Else
MsgBox "error setting the default printer"
End If

Else

MsgBox strPrinterName & " : printer not available"

End If

End Sub


Hope this helps and good luck with your project.

--
urkec
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 Printer aftamath77 Excel Discussion (Misc queries) 2 November 26th 08 05:37 PM
Printing to Local Printer and the not the default printer. [email protected] Excel Programming 1 September 13th 07 02:18 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
Default Printer Corey Excel Programming 1 May 30th 06 05:06 AM
Default Printer carlito_1985 Excel Programming 1 June 27th 05 08:27 AM


All times are GMT +1. The time now is 07:29 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"