I have written a code that takes multiple (up to 320 sheets) and simply saves them in specified folder as a PDF if data is present in a specific cell. It works great when we manually input the data, however when we copy the exact same data from another workbook it gives me a runtime error. Please note that the individual worksheets are hard-coded to a source worksheet that populates the input data. Here is the code I am using below:
Sub Sutherland_PDF()
Dim FolderPath As String
Dim i As Integer
Dim wb As ThisWorkbook
Set wb = ActiveWorkbook
FolderPath = "S:\_UCC Folder\UCCResults\Lindsay\"
Windows("UCC PDF Master Lindsay.xlsm").Activate
For i = 3 To Worksheets.Count
ThisWorkbook.Worksheets(i).Range("C17").WrapText = True
'since you are linking the data on the main excel sheet. It is placing a zero in all cells that have no data
'go to view and select immediate window then run the program you will see all of the pages that have something other than 0 listed
If ThisWorkbook.Worksheets(i).Range("C17").Value <> 0 Then
'Creates PDF from selected sheet
ThisWorkbook.Worksheets(i).ExportAsFixedFormat Type:=xlTypePDF, FileName:=FolderPath & ThisWorkbook.Worksheets(i).Name & "-" & ThisWorkbook.Worksheets(i).Range("D55").Value & "-" & ThisWorkbook.Worksheets(i).Range("C55").Value & ".pdf", OpenAfterPublish:=False
End If
Next
MsgBox "All Files have been saved to your S-Drive Folder. Have a Great Day!"
End Sub
Bookmarks