+ Reply to Thread
Results 1 to 5 of 5

Setting the default printer

Hybrid View

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    69

    Setting the default printer

    Hi there,

    I am trying to set the default printer using VBA and every time I run it I get a run time error because it doesn't like the name of the printer I am specifying. When I ran this macro:

    Sub get_printers()
    
    On Error Resume Next
    
    Set WshNetwork = CreateObject("WScript.Network")
    Set oPrinters = WshNetwork.EnumPrinterConnections
    For i = 0 To oPrinters.Count - 1 Step 1
    Cells(i + 1, 1) = "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i + 1)
    Next
    End Sub
    it tells me all my active printers and a list and the one I want to use is this:

    Port 10.1.70.## = \\network\RICOH Aficio MP C2500 PCL 6

    but when I use:

    Application.ActivePrinter = "\\network\RICOH Aficio MP C2500 PCL 6"
    or

    Application.ActivePrinter = "RICOH Aficio MP C2500 PCL 6"
    or

    Application.ActivePrinter = "\\network\RICOH Aficio MP C2500 PCL 6 On Port 10.1.70.##"
    I get these run time errors. Is there something wrong with how I am naming the default printer? Thanks for your help!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Setting the default printer

    What if you record a macro where you manually select the printer. Then use that recorded macro as a syntax guide.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Setting the default printer

    Hi AlphaFrog,

    This was already my first point of call but unfortunately when you record a macro and change the printer nothing registers in a macro. Likewise if you record a macro, change the printer and press the print button, nothing in the VBA code actually specifies what specific printer Excel should use; which is great for most purposes as it allows the OS to decide what printer to use but in this case it is important that a specific printer on a network is chosen to print the doc. And normally the Application.ActivePrinter = "PrinterName" should work for this

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Setting the default printer

    When setting a printer in Excel you need to include the port number, which will look something like NE01:, have a look here http://www.excelforum.com/tips-and-t...excel-vba.html it gets the required port for a given printer

  5. #5
    Registered User
    Join Date
    10-10-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2010
    Posts
    69

    Re: Setting the default printer

    Thanks Kylie123 I will give this a go!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Can I pass printer properties to the default printer?
    By rkjudy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2012, 04:11 PM
  2. Printing Macro Problem - Setting Default printer
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2012, 03:37 AM
  3. macro to print 2 copies to default printer, then 1 copy to Adobe PDF printer
    By jwright650 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2011, 01:07 PM
  4. setting PDF Creator as a default printer thro VBA macro
    By mvel_sky in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2010, 01:43 AM
  5. Setting default printer using wsh
    By PO in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1