I am trying to write a macro to print out multiple worksheets (in a particular order) into a pdf. I was trying to specify an array of worksheets via their Codename rather than the normal tab name but I keep running into a run time error '9' Subscript out of range. Below is the code: Some of the worksheets have two pages to print out, others have only one. Any help would be greatly appreciated.
VBA Code:
Dim theArray As Variant
theArray = Array("Sheet4", "Sheet2", "Sheet1", "Sheet3")
Worksheets("theArray").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & Application.PathSeparator & _
"test.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True