VBA CODE: Converting EXcel tabs to PDF but in specific sequence

gldurand

Board Regular
Joined
Jun 8, 2006
Messages
178
Office Version
  1. 2016
Platform
  1. Windows
Hi Friends

I have this code to convert Excel to PDF. I am selecting specific tabs from a larger workbook to create a number of different reports.

I want to be able to select certain tabs in specific order. But when creating the PDF it converts the tabs in the order they are found in the workbook. (Sheet1 -2 -3 -4 -5). Where i want as below


Sheets(Array("Sheet5", "Sheet2", "Sheet4", "Sheet3","Sheet1")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\glenn.durand\Desktop\Reports\Filename.pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

Any ideas?

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi Glenn,

As far as I know, you can't override the order of the sheets printed to pdf by the .ExportAsFixedFormat method.

One option would be to use VBA to copy your sheets into a temporary workbook > reorder the sheets > use Workbook.ExportAsFixedFormat to print the sheets in that order.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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