在vba中,shape对象代表一个图形。
多个图形可以组合成一个整体,称为组合图形。
在vba中GroupShapes对象代表一个组合图形。
在vba中,可以使用Shape对象的GroupItems属性返回一个组合图形对象GroupShapes。
在使用GroupItems属性返回一个组合图形对象之前,需要先用Shape对象的Type属性判断是否为组合图形。
使用GroupShapes对象的Item方法还可返回组合图形中的单个图形。
基于以上的认识可以使用如下的代码批量设置修改ppt中组合图形的的各种格式:
Sub QQ1722187970()
'形状对象
Dim oShape As Shape
'幻灯片对象
Dim oSlide As Slide
'返回文本区域对象
Dim oRng As TextRange
Dim oShapes As GroupShapes
Dim oTable As Table
Dim oCell As Cell
Dim oPPT As Presentation
Set oPTT = PowerPoint.ActivePresentation
With oPTT
For Each oSlide In .Slides
With oSlide
For Each oShape In .Shapes
With oShape
'判断是否为组合图形
If .Type = msoGroup Then
Set oShapes = .GroupItems
'遍历组合图形中的每个图形
For Each oGShape In oShapes
With oGShape
If .HasTextFrame Then
Set oRng = .TextFrame.TextRange
With oRng.Font
'各种格式设置
.Color = vbRed
End With
End If
End With
Next
End If
End With
Next
End With
Next
End With
End Sub


发表评论