I am trying to print multiple sheets in PDF Format. Below is the code but it is giving subscript out of range error. Please help
PdfFile = ActiveWorkbook.FullName
Worksheets("Report").PageSetup.Orientation = xlLandscape
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = "SPC Report " & Format(Now, "dd-mmm-yy h-mm-ss") & ".pdf" 'PdfFile & "_" & Worksheets("Report").name & ".pdf"
' Export activesheet as PDF
With Worksheets("Report")
ThisWorkbook.Sheets(ShtNames).Select
.ExportAsFixedFormat Type:=xlTypePDF, Filename:="SPC Report " & Format(Now, "dd-mmm-yy h-mm-ss") & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ThisWorkbook.Sheets("Report").Select
End With
Here is where I declare ShtNames and assign values to it.
Dim ShtNames() As String
ReDim ShtNames(1 To ActiveWorkbook.Sheets.Count / 2 + 1)
i = Sheets.Count
j = 1
Do While i > Sheets.Count / 2
ShtNames(j) = Sheets(i).Name
i = i - 1
j = j + 1
Loop