Printer select question.

Taffer

New Member
Joined
Jan 10, 2010
Messages
18
Why am I getting this error when using this application? I can't seem to track why this is triggering an error.

run-time error, '1004':, method, 'ActivePrinter', object, '_Application', failed

Code:
Sub PrinterSelect()
    Dim PrinterFullName As String
 
    If CampusCardAHcbx.Value = "H" Then
        PrinterFullName = "H3005_S1DIETMGR_131_216 on 3"
    ElseIf CampusCardAHcbx.Value = "O" Then
        PrinterFullName = "H3005_O1_19_182 on 2"
    ElseIf CampusCardAHcbx.Value = "K" Then
        PrinterFullName = "H4345_T1_203_53 on 1"
    Else
        PrinterFullName = "H9050_O7300_2CPYCNTR_35_51 on PS03"
    End If
 
  [COLOR=red][B]  Excel.Application.ActivePrinter = PrinterFullName[/B][/COLOR]
 
    '---------------------------------------------------------------------
    '- IF PRINTER FOUND
    If Err.Number = 0 Then
        If CampusCardAHcbx.Value = "H" Or CampusCardAHcbx.Value = "O" Or CampusCardAHcbx.Value = "K" Then
            '-----------------------------------------------------------------
            'ALTERNATIVE LINES OF CODE TO SAVE PAPER WHEN TESTING
            'Sheets("Order Ticket").PrintOut            ' PRINT SHEET
            Sheets("Order Ticket").PrintPreview       ' PRINT PREVIEW TO TEST
            '-----------------------------------------------------------------
            MsgBox ("Printed on printer" & vbCr & PrinterFullName & "to" & CampusCardAHcbx.Value)
        Else
 
            MsgBox ("Printed on printer" & vbCr & PrinterFullName & " to Service Center Printer")
        End If
    Else
        Err.Clear   ' clear for next error
        MsgBox (PrinterFullName & vbCr & "Error: Printer not found")
    End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Derek Brown

Well-known Member
Joined
Dec 26, 2005
Messages
2,390
You may find that there should be a ":" at the end of the printer name.
Try setting that printer as your default printer, in Control Panel, and then use the Immediate Window to print the name:
? Excel.Application.ActivePrinter

Don't forget to reset the default printer afterwards.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,610
Messages
5,832,693
Members
430,153
Latest member
Javid_P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top