I\'m trying to write a small function that takes in a filepath (where the workbook was saved at), targetpath (where the pdf will be saved to), and a string of tab names (pip
Use WBO.Sheets
instead of WBO.Worksheets
in the loop.
Verify that WSO.Visible = xlSheetVisible
to filter out hidden sheets.
There's two problems with the For Each loop: it doesn't grab any sheets such as "Chart1", it only grabs sheets such as "Sheet1"
Charts and Worksheets are two different collections.
Try this:
Sub Demo()
Dim oWs As Worksheet
Dim oCs As Chart
For Each oWs In ActiveWorkbook.Worksheets
Debug.Print oWs.Name
Next
For Each oCs In ActiveWorkbook.Charts
Debug.Print oCs.Name
Next
End Sub