简体   繁体   English

使用VBA创建基于PPT中用户输入的模板,以创建,添加文本框和格式化幻灯片的格式

[英]Creating a template to create, add, and format text boxes to a slide based on user input in PPT using VBA

I have another questions that asks about the logic behind using several boolean radio buttons to ask survey questions, located here . 我还有另外一个问题,该问题位于此处 ,使用几个布尔单选按钮询问调查问题背后的逻辑。 The largets issue I have had was getting the text boxes to populate a separate slide to display the systems that will affect the customer based on their radio button input. 我遇到的最大问题是让文本框填充一张单独的幻灯片,以根据单选按钮输入显示将影响客户的系统。

This post is an attempt to find a way to reduce the code needed to create, place, and format the text boxes. 这篇文章试图找到一种减少创建,放置和格式化文本框所需代码的方法。 The below code is what I have so far, but it keeps telling me it expects an "=" when I run it. 下面的代码是我到目前为止所拥有的,但是一直告诉我在我运行它时希望它是一个“ =”。

Public Sub textBox(t As Integer, l As Integer, w As Integer, h As Integer, Sys As String)
Dim myTB As Shape

With ActivePresentation.Slides(7)
   Set myTB = .Shapes.AddTextbox(msoTextOrientationHotizontal, l, t, w, h)
   myTB.TextFrame.TextRange.Text = Sys
   myTB.TextFrame.TextRange.Font.Color.RGB = RGB(255,255,255)
   myTB.TextFrame.TextRange.Font.Size = 20
End With

End Sub

I think I may have the logic wrong in declaring the variables. 我认为声明变量的逻辑可能有误。 What I want to be able to do is simply place textBox(200,300,200,25, "ERP Name") into my If Then or Case statement to format the boxes. 我想要做的只是将textBox(200,300,200,25,“ ERP名称”)放入我的If Then或Case语句中以格式化框。 Is there a better way to do this? 有一个更好的方法吗?

You'd need to use 您需要使用

CALL textBox(parm, parm, ... , parm) 

or leave out the parentheses. 或省略括号。

For clearing everything out, here's a starting point: 为了清除所有内容,这是一个起点:

Sub ClearTheField()

Dim oSl As Slide
Dim oSh As Shape

For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes
        If oSh.Type = msoOLEControlObject Then
            If Left$(oSh.OLEFormat.Object.Name, Len("TextBox")) = "TextBox" Then
                oSh.OLEFormat.Object.Text = ""
            End If
            If Left$(oSh.OLEFormat.Object.Name, Len("CheckBox")) = "CheckBox" Then
                oSh.OLEFormat.Object.Value = False
            End If
            If Left$(oSh.OLEFormat.Object.Name, Len("CommandButton")) = "CommandButton" Then
                oSh.OLEFormat.Object.Caption = "I changed too"
            End If

        End If
    Next
Next

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM