I am trying to generate a single PDF from a single sheet (within one workbook) based on if that sheet has a 1 in A1. Only one of the 10 hidden sheets will ever have a 1 in A1 depending on what is filled in on the front sheet ("Calculator" / "Sheet1").
The code I have does generate the PDF but doesn't change the active sheet, so rather than jumping to the instance of the sheet with 1 in A1 it prints the sheet I was last on.
Sub GenPDF_OTJ()
Dim saveInFolder As String
Dim replaceSelected As Boolean
Dim wsName As Variant
Dim iVis As XlSheetVisibility
saveInFolder = "C:\Downloads\pdf\"
If Right(saveInFolder, 1) <> "\" Then saveInFolder = saveInFolder & "\"
With ThisWorkbook
replaceSelected = True
For Each wsName In Array("OTJ Bus Admin", "OTJ SFSCA", "OTJ Sales L4") 'additional sheets to be added in once working
If .Worksheets(wsName).Range("A1").Value > 0 Then 'A1 will only be 1 or 0
.Worksheets(wsName).Select replaceSelected
replaceSelected = False
End If
Next
.ActiveSheet.Select
With .ActiveSheet
iVis = .Visible
.Visible = xlSheetVisible
.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=PdfFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
.Visible = iVis
.Visible = xlSheetHidden
End With
End With
End Sub