PDF Export/Printer Ports

jrussellpowell

New Member
Joined
Dec 15, 2009
Messages
1
Ok, I have been trying to sort this out on my own all day with no success, so maybe someone here can help.

I have a workbook setup with multiple sheets. Each section has an export button created for it which links to a user form. The user form gives 2 options: export to PDF & export as a Microsoft Document Image. I am having the same issue with both, so I will explain the PDF.

The PDF "export" is being done with PDFCreator which works as a printer like Primo PDF or Cute PDF. I can write the macro and get it working fine for myself, but this workbook will also be used by other people. They have the same PDF program, but it is not working on the same printer port. I have tried to use the get error command to get around this, with no luck.

Essentially what I need is the code to do is: try to print on "PDFCreator on Ne01:", if it succeeds, then end the sub, if it fails, try to print to "PDFCreator on Ne02:", if it fails....etc. Basically, I want it to keep trying on each port in a range until it finds the one that works.

Can anyone help? Here is the lousy code I have put together so far:

Private Sub CommandButton3_Click()
On Error GoTo ERR_Handler
AIBUExportType.Hide
Sheets(Array("AIB (1)", "AIB (2)", "AIB (3)")).Select
Sheets("AIB (1)").Activate
Application.ActivePrinter = "PDFCreator on Ne00:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne00:", Collate:=True
Sheets("AIB (1)").Select
Exit Sub

ERR_Handler:
On Error GoTo ERR_Handler2
Application.ActivePrinter = "PDFCreator on Ne00:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne00:", Collate:=True
Sheets("AIB (1)").Select
Exit Sub

ERR_Handler2:
On Error GoTo ERR_Handler3
Application.ActivePrinter = "PDFCreator on Ne02:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne02:", Collate:=True
Sheets("AIB (1)").Select
Exit Sub

ERR_Handler3:
On Error GoTo ERR_Handler4
Application.ActivePrinter = "PDFCreator on Ne03:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne03:", Collate:=True
Sheets("AIB (1)").Select
Exit Sub

ERR_Handler4:
On Error GoTo 0
Application.ActivePrinter = "PDFCreator on Ne04:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne04:", Collate:=True
Sheets("AIB (1)").Select

End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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