0

我在 PowerPoint 演示文稿的幻灯片母版中有一个命令按钮和一个文本框。我正在尝试检索 PowerPoint 的属性,例如 SlideID、SlideIndex 和相应文件的名称,并在单击命令按钮时将它们发布到文本框中。

目前我有这段代码,但它给了我一个错误:

Sub CommandButton1_Click()
   Dim Index As Long
   Dim SlideId as Long
   Dim FileName as String 

   TextBox1.Text = "SlideIndex:" & Index & "Slide ID:" & SlideId 

End Sub

我希望电源点的第 1 页读取为 slideIndex 1 SlideID 1 和文件名。对于幻灯片 2,我希望它说所有的两个,依此类推......

提前致谢!

4

1 回答 1

0

如果您愿意,可以使用命令按钮;或者您可以使用您想要绘制的任何 PowerPoint 形状,为其分配运行宏的动作设置,然后选择您希望它在单击时运行的宏。

无论哪种方式,这应该工作:

Sub ReportStuff()

    Dim oSl As Slide
    Dim oSh As Shape

    Set oSl = SlideShowWindows(1).View.Slide

    ' Test to see if the shape's already there:
    Set oSh = IsItThere(oSl, "My Text Box")

    ' If it's not there, add it:
    If oSh is Nothing Then
       Set oSh = oSl.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 50)
       oSh.Name = "My Text Box"
    End If

    With oSh.TextFrame.TextRange
        .Text = "Index: " & oSl.SlideIndex & " ID: " & oSl.SlideID & " File: " & ActivePresentation.FullName
    End With

End Sub

Function IsItThere(oSl as Slide, sName as String) as Shape
   Dim oSh as Shape
   For each oSh in oSl.Shapes
      If oSh.Name = sName Then
         Set IsItThere = oSh
         Exit Function
      End If
   Next
End Function
于 2015-05-15T15:21:58.413 回答