在powerpoint中创建一个填充变量

时间:2014-01-31 09:41:58

标签: vba powerpoint-vba

在单词中我使用以下内容从单词中指定区域的输入框插入文本:

Sub OpenWord()


   Dim var1 As String
   var1 = InputBox("vul!")

   Documents.Open ("C:\Documents and Settings\aa471714\Desktop\TEMP BESTANDEN/Doc2.doc")
   ActiveDocument.Bookmarks("Test").Select
   Selection.Text = var1


End Sub

我知道想为powerpoint中的某些东西创建相同的功能。所以我在word中做了(将单词中的书签区域分类为“test”,然后在那里填写变量)也想在powerpoint中进行。以某种方式定义一个对象,以便我可以在那里填写一个变量。

有人知道如何在PPT中做到这一点吗?

1 个答案:

答案 0 :(得分:1)

这是您需要的基础知识。

Sub WriteToTextBox()
Dim tb As Shape
Dim sld As Slide
Dim pres As Presentation
Dim var1 As String


var1 = InputBox("Var1")
Set pres = ActivePresentation
Set sld = pres.Slides(23) 'Modify as needed

Set tb = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 100, 50) 'Modify dimensions as needed
    tb.name = "unique name"  '< assign a unique name to the textbox so you can refer to it later
    tb.TextFrame.TextRange.Text = var1



End Sub

Sub ReadFromTextBox()
Dim s$
Dim sld As Slide
Dim pres As Presentation
Set pres = ActivePresentation
Set sld = pres.Slides(23) 'Modify as needed


s = sld.Shapes("unique name").TextFrame.TextRange.Text 'Read the value from the textbox
MsgBox s 

End Sub