VBA Refer to worksheet vs chart sheet

后端 未结 2 407
栀梦
栀梦 2021-01-05 17:46

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

相关标签:
2条回答
  • Use WBO.Sheets instead of WBO.Worksheets in the loop.

    Verify that WSO.Visible = xlSheetVisible to filter out hidden sheets.

    0 讨论(0)
  • 2021-01-05 18:38

    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
    
    0 讨论(0)
提交回复
热议问题