excel 提取Powerpoint图表的最小值和最大值

lyfkaqu1  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(141)

我试图创建一个VBA代码,它可以帮助我打开一个演示文稿,转到每个幻灯片,检查一个图表,然后复制其最小值和最大值在Excel工作表。我有一个40+幻灯片演示文稿与多个图表,这个代码将帮助我检查是否在所有图表轴值是一致的。下面是我正在工作的代码。到目前为止,能够打开演示文稿,但无法打开图表并将值复制到Excel。请帮助,VBA编码新手

Sub CopySlidechart()

    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim ppSlide As PowerPoint.Slide
    Dim ppPlaceHolder As PowerPoint.Shape
    Dim oRow As Long

    Set ppApp = CreateObject("PowerPoint.Application")
    Set ppApp = New PowerPoint.Application
    ppApp.Visible = msoTrue
    
    Dim input_path As String
    input_path = ThisWorkbook.Worksheets("Sheet1").Range("B1")

    Set ppPres = ppApp.Presentations.Open(input_path)

    oRow = 6
    For Each ppSlide In ppPres.Slides
        For Each ppPlaceHolder In ppSlide.Shapes
            If ppPlaceHolder.HasChart Then
            ThisWorkbook.Worksheets("Sheet1").Range(oRow, "B").Value = ChartObject.Chart.Axes(xlCategory).MaximumScale
            ThisWorkbook.Worksheets("Sheet1").Cells(oRow, "C").Value = ChartObject.Chart.Axes(xlCategory).MinimumScale
    oRow = oRow + 1
                oRow = oRow + 1
                Exit For
            End If
        Next ppPlaceHolder
    Next ppSlide

End Sub
vhmi4jdf

vhmi4jdf1#

尝试以下代码。Powerpoint中没有ChartObject,只有Chart(类似于Excel中的ChartObject.Chart)。请注意,您需要检查Axes(xlValue),因为您希望从y轴读取min和max。

Dim ws As Worksheet
set ws = ThisWorkbook.Worksheets("Sheet1") 
oRow = 6
For Each ppSlide In ppPres.Slides
    For Each ppPlaceHolder In ppSlide.Shapes
        If ppPlaceHolder.HasChart Then
            Dim chart as Chart, axis as Axis
            Set chart = ppPlaceHolder.Chart
            Set axis = chart.Axes(xlValue)

            ws.Range(oRow, "B").Value = axis.MaximumScale
            ws.Range(oRow, "C").Value = axis.MinimumScale
            oRow = oRow + 1
        End If
    Next ppPlaceHolder
Next ppSlide

相关问题