遍历全部幻灯片及每一个幻灯片的形状对象:,下面我们就来说一说关于ppt如何用vba实现复选框?我们一起去了解并探讨一下这个问题吧!

ppt如何用vba实现复选框(PPTVBA获取当前幻灯片并设置其全部对象的属性和段落格式)

ppt如何用vba实现复选框

遍历全部幻灯片及每一个幻灯片的形状对象:

Dim oPres As Presentation Set oPres = Application.ActivePresentation Dim oSlide As Slide Dim oShape As Shape For Each oSlide In oPres.Slides……Next For Each oShape In oSlide.Shapes……Next

当然,如果你只想设置其中的某一张幻灯片,或其中的第j个对象,可以把上面代码的两个循环去掉,具体指定幻灯片索引号和第j个对象即可:

i = oPres.Slides.Count j = 0 '设置最后一个幻灯片或指定幻灯片的第一个对象的字体和段落格式 Set oSlide = oPres.Slides.Item(i) Set oShape = oSlide.Shapes.Item(1)

如果只想获取当前幻灯片并设置其全部对象的属性和段落格式,PPT VBA并没有提供ActiveSlide对象,但通过以下对象层次及属性可以获得当前幻灯片的索引号:

Application.ActiveWindow.View.Slide.SlideNumber

获取当前幻灯片并设置其全部对象的属性和段落格式的代码:

Sub oneSlideAllShapes() 'On Error Resume Next '对象和变量声明 Dim oPres As Presentation Set oPres = Application.ActivePresentation Dim oSlide As Slide Dim oShape As Shape Dim tr As TextRange Dim i As Long, j As Long Dim k As Integer '当前幻灯片索引号 k = Application.ActiveWindow.View.Slide.SlideNumber For Each oShape In oPres.Slides(k).Shapes If oShape.TextFrame.HasText = msoTrue Then Set tr = oShape.TextFrame.TextRange With tr.Font .NameAscii = "宋体" .NameFarEast = "宋体" .Size = 20 '.Color.SchemeColor = ppBackground ' .Color.RGB = RGB(Red:=0, Green:=0, Blue:=0) .Bold = msoFalse End With tr.ParagraphFormat.SpaceWithin = 1.1 '设置行距 Set tr = Nothing End If 'oShape.Fill.Background '文本框背景色用幻灯片背景填充 'oShape.TextFrame.TextRange.IndentLevel = 1 Next '对象删除 Set oShape = Nothing Set tr = Nothing Set oSlide = Nothing Set oPres = Nothing End Sub

-End-

,