使用 CommandButton VBA 将 PowerPoint 幻灯片添加到文本框 [英] Add PowerPoint slide to textbox with CommandButton VBA

查看:49
本文介绍了使用 CommandButton VBA 将 PowerPoint 幻灯片添加到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a command button and a text-box in the Slide Master of a PowerPoint presentation. I am trying to retrieve the PowerPoint's properties such as SlideID, SlideIndex and the name of the corresponding file and post them to the text box on the click of the command button.

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

At the moment I have this code but its giving me an error:

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,我希望它说所有两个等等......

I want page 1 of the power point to read as slideIndex 1 SlideID 1 and the file name. and for slide 2 I want it to say all two's and so on...

提前致谢!

推荐答案

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

You can use a command button if you like; or you can use any PowerPoint shape you want to draw, assign it an Action Setting of Run Macro and choose the macro you want it to run when clicked.

无论哪种方式,这都应该有效:

Either way, this should work:

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

这篇关于使用 CommandButton VBA 将 PowerPoint 幻灯片添加到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆