2013年2月1日 星期五

[Visual Basic] Get Excel Chart Count in all WorkSheets




Imports Excel = Microsoft.Office.Interop.Excel

Module Module1

    Sub Main()
        Dim oExcel As Excel.Application
        Dim oWorkbook As Excel.Workbook
        Dim oWorksheet As Excel.Worksheet
        Dim chart_count As Integer
        Dim oChart As Excel.ChartObjects
        oExcel = CreateObject("Excel.Application")
        oExcel.Visible = True
        oExcel.DisplayAlerts = False

        oWorkbook = oExcel.Workbooks.Open("F:\Google 雲端硬碟\pythonprogram\Bugzilla_Issue_Summary_VT58.xlsm")
        For Each oWorksheet In oWorkbook.Worksheets
            'Console.Write(oWorksheet.Name)
            oChart = oWorksheet.ChartObjects()
            chart_count = oChart.Count
            MsgBox(oWorksheet.Name & "Chart:" & chart_count)
        Next

        'oWorkbook.Save()
        oWorkbook.Close()
        oExcel.Quit()

    End Sub

End Module

沒有留言: