I have had a piece of code in operation for over 3 years. Suddenly on July 28th, 2016, it stopped working.
It is very simple and I hope it is an easy solve
I had VBA that was working perfectly until the first week of August, then my PDFs only had the first page. I was using a similar method as you - where I'd select many worksheets. I did a work around using an array. My code was within a form, but I'll post here for reference.
Private Sub CommandButton2_Click()
Dim PrintArray() As Variant
'I used a form to select with checkboxes which worksheets to print, so this code would go inside the form linked to a command button
ReDim Preserve PrintArray(1 To 1)
PrintArray(1) = "Sheet 1 Name"
j = 1
If Sheet2.Value = True Then 'I used a checkbox to select which worksheets to print, but you could use any conditional statement here
j = j + 1
ReDim Preserve PrintArray(1 To j)
PrintArray(j) = "Sheet 2 Name"
End If
If Sheet3.Value = True Then 'I used a checkbox to select which worksheets to print, but you could use any conditional statement here
j = j + 1
ReDim Preserve PrintArray(1 To j)
PrintArray(j) = "Sheet 3 Name"
End If
'You could add as many pages and conditions as you need....
Unload Me 'because I was using a form
Sheets(PrintArray).Select
'Creates the PDF file name
FileNameforSave = "Name of New File" & ".pdf"
'Save file as a PDF
ActiveSheet.ExportAsFixedFormat xlTypePDF, Filename:= _
FileNameforSave, _
Quality:=xlQualityStandard, IncludeDocProperties:= _
True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub