I`m trying to save all the worksheets from the workbook as one single pdf (all sheets combined in one pdf) except for two worksheets that are not needed in the pdf which have the names of "Raw" and "Tables". I have one code, but when I run it I do not see the saved file even though the code runs successfully. What am I doing wrong or is there an easier way to tacklethis? Thanks!
Sub CombineWorksheetsAsPDF()
Dim wb As Workbook
Dim ws As Worksheet
Dim saveFolderPath As String
Dim pdfFileName As String
Dim wsNamesToExclude As String
Dim wsNamesArray As Variant
Dim i As Long
Dim pdfFilePath As String
saveFolderPath = "C:\Users\j\Documents" ' Change this!!!!!
Application.ScreenUpdating = False
Set wb = ActiveWorkbook
pdfFileName = Left(wb.Name, InStrRev(wb.Name, ".")) & ".pdf"
wsNamesToExclude = "Raw,Tables" ''exclude these tabs
wsNamesArray = Split(wsNamesToExclude, ",")
pdfFilePath = saveFolderPath & pdfFileName
If Dir(pdfFilePath) <> "" Then
Kill pdfFilePath
End If
For Each ws In wb.Sheets
If Not IsInArray(ws.Name, wsNamesArray) Then
ws.Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfFilePath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End If
Next ws
Application.ScreenUpdating = True
MsgBox "PDF seved in: " & saveFolderPath, vbInformation
End Sub
Function IsInArray(ByVal valToBeFound As String, arr As Variant) As Boolean
Dim element As Variant
On Error Resume Next
IsInArray = (UBound(Filter(arr, valToBeFound)) > -1)
On Error GoTo 0
End Function
Export Sheets to Single PDF