【发布时间】:2020-07-03 06:39:30
【问题描述】:
我是 vba 的新手,需要一些指导。我正在尝试为每张幻灯片(在幻灯片区域之外)添加一个文本框,以便快速查看幻灯片的 ID 和索引。我拼凑了几个位来创建下面的代码。它可以工作,但是添加到每张幻灯片的文本框数量是演示文稿中的幻灯片数量(112)而不是 1。我还想知道如何调整它以在更改幻灯片时进行刷新。
提前致谢!
代码如下:
Sub AddSlideInfo()
'Original Source: http://www.pptfaq.com/FAQ01180-Add-presentation-file-name-to-each-slide-master.htm
Dim x As Long
Dim oSh As Shape
Dim oSl As Slide
With ActivePresentation
On Error Resume Next 'In case the shape does not exist.
' On each slide in the presentation:
For x = 1 To .Slides.Count
Set oSl = ActivePresentation.Slides(x)
' Create a textbox at 0" from left,
' -120.24 points from top of slide ( -1.67") from top left corner
' Make it 90 points high, 300 points wide 1.25" x 5.5"
' Change any of these numbers at will
For Each oSl In ActivePresentation.Slides
With oSl
Set oSh = .Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, Left:=0, Top:=-120, Width:=300, Height:=90)
' Give it a name so we can find it later
oSh.Name = "SlideInfo"
'Add some formatting and dummy text
With oSh.TextFrame.TextRange
.Font.Name = "Berlin Sans Demi"
.Font.Size = 12
.Text = _
"Slide Info: " & vbNewLine & _
"Slide Index: " & oSl.SlideIndex & vbNewLine & _
"Slide ID: " & oSl.SlideID
End With
End With
Next
Next x
End With
End Sub
【问题讨论】:
标签: vba powerpoint