Attribute VB_Name = "Main" Option Explicit Dim Prt_On As String Function NetworkPrinter(ByVal myprinter As String) On Error Resume Next Dim NetWork As Variant Dim X As Integer Prt_On = " On " '/// Define NetWork Array \\\ NetWork = Array("Ne00:", "Ne01:", "Ne02:", "Ne03:", "Ne04:", _ "Ne05:", "Ne06:", "Ne07:", "Ne08:", _ "Ne09:", "Ne10:", "Ne11:", "Ne12:", _ "Ne13:", "Ne14:", "Ne15:", "Ne16:", _ "LPT1:", "LPT2:", "File:", "SMC100:", _ "XPSPort:") 'Setup printer to Print X = 0 TryAgain: On Error Resume Next 'Printer Application.ActivePrinter = myprinter & Prt_On & NetWork(X) If Err.Number <> 0 And X < UBound(NetWork) Then X = X + 1 GoTo TryAgain ElseIf Err.Number <> 0 And X > UBound(NetWork) - 1 Then GoTo PrtError End If On Error GoTo 0 NetworkPrinter = myprinter & Prt_On & NetWork(X) errorExit: Exit Function PrtError: 'no printer found NetworkPrinter = "" Resume errorExit End Function Sub PrintToPDF(sPDFFileName, SheetName) Dim sPSFileName As String 'Name of PS to be created ' Dim sPDFFileName As String 'Name of PDF to be created Dim sJobOptions As String Dim sCurrentPrinter As String 'Same current printer choice to resume at end Dim sPDFVersionAndPort As String 'Version of Adobe Dim sDummyPrinter As String ' Need a dummy printer to produce the PS Dim appDist As cAcroDist Set appDist = New cAcroDist sCurrentPrinter = Application.ActivePrinter 'Save the currently active printer sDummyPrinter = NetworkPrinter("Dummy Printer Name") ' Change this to match an installed PS-capable printer driver Application.ActivePrinter = sDummyPrinter sPSFileName = ThisWorkbook.Path & ThisWorkbook.Name & ".ps" 'Name of PS file ThisWorkbook.Sheets(SheetName).PrintOut ActivePrinter:=sDummyPrinter, _ PrintToFile:=True, PrToFileName:=sPSFileName 'Prints to PS sPDFVersionAndPort = NetworkPrinter("Adobe PDF") Application.ActivePrinter = sPDFVersionAndPort Call appDist.odist.FileToPDF(sPSFileName, sPDFFileName, sJobOptions) 'Creates PDF On Error Resume Next Kill sPSFileName 'Removes PS On Error GoTo 0 Application.ActivePrinter = sCurrentPrinter 'Change back to the original printer End Sub