VBA获取图表水平轴名称/标题

VBA获取图表水平轴名称/标题,vba,powerpoint,Vba,Powerpoint,我正试图编写代码来提取水平分类轴标签,这里是“成员共享(p=30070)”。整个过程是power point幻灯片的一部分 Function GetShapeDetails(pptshp As PowerPoint.Shape) Dim shp As PowerPoint.Shape Dim txt As String If pptshp.HasTextFrame Then txt = pptshp.TextFrame.TextRange Debug.Print "Shape

我正试图编写代码来提取水平分类轴标签,这里是“
成员共享(p=30070)
”。整个过程是power point幻灯片的一部分

Function GetShapeDetails(pptshp As PowerPoint.Shape)
  Dim shp As PowerPoint.Shape
  Dim txt As String
  If pptshp.HasTextFrame Then txt = pptshp.TextFrame.TextRange

  Debug.Print "Shape Name - " & pptshp.Name & " / Shape Type - " & pptshp.Type & " / Text - " + txt

  If pptshp.Type = msoGroup Then
    For Each shp In pptshp.GroupItems
      GetShapeDetails shp
    Next shp
  End If


If pptshp.Type = msoTable Then

If pptshp.HasTable Then
Debug.Print "*** Table Details Start ***"
Debug.Print "Table Rows count -  " & pptshp.Table.Rows.Count

For i = 1 To pptshp.Table.Rows.Count
    For j = 1 To pptshp.Table.Columns.Count
        Debug.Print pptshp.Table.cell(i,    j).Shape.TextFrame.TextRange.Text
    Next j
Next i
Debug.Print "*** Table Details End ***"
End If

End If


If pptshp.Type = msoChart Then

If pptshp.HasChart Then
Debug.Print "*** Chart Details Start ***"

        For Each sc In pptshp.Chart.SeriesCollection
            For Each d In sc.DataLabels
            Debug.Print d.Text
            Next
        Next

        With pptshp.Chart.Axes(xlCategory, xlPrimary)
         If .HasTitle Then Debug.Print .AxisTitle.Characters.Text
        End With

        With pptshp.Chart.Axes(xlValues, xlPrimary)
         If .HasTitle Then Debug.Print .AxisTitle.Characters.Text
        End With

Debug.Print "*** Chart Details End ***"
End If

End If

End Function
除读取图表数据的部分外,上述所有功能均正常工作。这不是获取水平类别轴标签。请任何人在这里帮助我

Debug.Print "xlcategory Title -  " & pptshp.Chart.Axes(xlCategory, xlPrimary) _
    .HasTitle & pptshp.Chart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text
如果没有标题,那么在尝试访问其文本时将出现错误。请尝试以下方法:

With pptshp.Chart.Axes(xlCategory, xlPrimary) _
     If .HasTitle Then Debug.Print .AxisTitle.Characters.Text
End With

您是否在这里使用
&
作为逻辑运算符?在VBA中不能这样做。

实际输出是什么?@TimWilliams它给了我一个错误在这种情况下,实际错误是什么?我使用&作为串联运算符。无论如何,我的要求是提取图像中金星旁边的文本,在本例中为“成员共享”。我尝试了你的代码,它给了我一个自动错误(未指定的错误)。你能从图表中读取任何属性吗?您没有发布太多的代码,因此很难知道还会发生什么。