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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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
Back
Top