Share via

Print On A Selected Printer

Anonymous
2012-02-14T20:52:17+00:00

Printer macro getting runtime error 1004: Method 'ActivePrinter' of object '_application' failed.

Also need a line for property Not to print on both sides.

Printer name is correct. 

Sub ColorPrinter()

    Application.ActivePrinter = "\\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL"

    ActiveWindow.SelectedSheets.PrintOut Copies:=1

End Sub

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-02-16T04:14:01+00:00

Hi,

The ActivePrinter property returns an active printer name string just like below:

\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL on Ne02:

From the above string, we can see that " on Ne02:" is added at the end of "\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL".

Please use the following function to set your network printer name:

'#######################################################

'Returns the full network printer name.

'If you want the function to change the active printer,

'blnToChange must set to value of True.

'#######################################################

Function MatchFullNetworkPrinterName(ByVal strNetworkPrinterName As String, Optional ByVal blnToChange As Boolean = False) As String

    Dim strCurrentPrinterName   As String

    Dim strTempPrinterName      As String

    Dim i                       As Long

    strCurrentPrinterName = Application.ActivePrinter

    i = 0

    Do While i < 100

        strTempPrinterName = strNetworkPrinterName & " on Ne" & Format(i, "00") & ":"

        '/* Try to change to the network printer. */

        On Error Resume Next

        Application.ActivePrinter = strTempPrinterName

        '/* Resets last exception-handler location to Nothing, disabling the exception. */

        On Error GoTo 0

        '/* If the network printer was found. */

        If Application.ActivePrinter = strTempPrinterName Then

            MatchFullNetworkPrinterName = strTempPrinterName

            Exit Do

        End If

        i = i + 1

    Loop

    '/* Change back to the original printer. */

    If Not blnToChange Then Application.ActivePrinter = strCurrentPrinterName

End Function

e.g

Sub Test()

    Dim strPntName As String

    strPntName = MatchFullNetworkPrinterName("\naeajaxsps06v\JAX-BL919-FL2-RM69-HPCP4525PCL", True)

    If strPntName <> "" Then MsgBox "The active printer has been changed successfully!", vbOKOnly, "Tips"

End Sub

Have a great day!

Cristin Yan

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-17T03:16:24+00:00

    Hi,

    Your original post (http://answers.microsoft.com/thread/4658715c-eb39-45df-9cf7-98d37072779c) has been deleted as you got answered from here.

    If you have any questions, please feel free to let me know!

    Cristin Yan

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-02-16T12:52:43+00:00

    Cristin, Thanks for the help.

    Was this answer helpful?

    0 comments No comments