我正在尝试编写代码以提取水平类别轴标签,此处为“ Member Share (p=30070)
”。整个过程是幻灯片的一部分。
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
除了读取图表数据的部分以外,上述所有功能均有效。这不会获取“水平类别轴标签”。请任何人在这里帮助我。
答案 0 :(得分:0)
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中做到这一点。