简体   繁体   English

PowerPoint-如何在以下幻灯片中显示幻灯片1组合框中的值?

[英]PowerPoint - How to display the Value from Slide 1 ComboBox in following slides?

I want to select a "Type" of presentation on the first slide, like "Private", "Public", "Confidential", etc. in an ActiveX Combobox and have the selected value show at the bottom of future slides in an ActiveX TextBox. 我想在第一张幻灯片上选择演示文稿的“类型”,例如ActiveX组合框中的“私人”,“公共”,“机密”等,并在ActiveX文本框中的以后的幻灯片的底部显示选定的值。

I have the Slide 1 Combobox working fine. 我的Slide 1组合框工作正常。 I run the presentation, get focus, pull-down and select my value. 我运行演示文稿,获取焦点,下拉列表并选择我的值。 It is ComboBox1. 它是ComboBox1。

I can't seem to find the trick to reference that Value in future slides. 我似乎找不到在将来的幻灯片中引用“价值”的窍门。 Extremely novice in vb. VB中的新手。 Not sure I'm using the PowerPoint vb editor properly. 不确定我是否正确使用PowerPoint vb编辑器。 Seems my code/values are just limited to the current slide and not future slides. 似乎我的代码/值仅限于当前幻灯片而不是将来的幻灯片。

On slide 2 I have TextBox1 defined. 在幻灯片2上,我定义了TextBox1。 I can get it to take a value with TextBox1.Value = "This is a " & ComboBox1 & " slide." 我可以使用TextBox1.Value =“这是一个&ComboBox1&”幻灯片。 But all that displays is "This is a slide". 但是显示的只是“这是一张幻灯片”。 I've tried everything I can't find a way to reference that first slide ComboBox1 value but I can't. 我已经尝试了所有无法找到引用第一个幻灯片ComboBox1值的方法,但我做不到。

Is it possible? 可能吗?

Thanks! 谢谢!

Inserting source. 插入源。

This is working on Slide 1. 这正在幻灯片1上进行。

Option Explicit
Private Sub ComboBox1_GotFocus()
If ComboBox1.ListCount = 0 Then AddDropDownItems
MsgBox "Currently:" & ComboBox1.Value
End Sub

Sub AddDropDownItems()
ComboBox1.AddItem "Private"
ComboBox1.AddItem "Confidential"
ComboBox1.AddItem "Secret"
ComboBox1.AddItem "Public"
ComboBox1.AddItem "Test"
ComboBox1.ListRows = 5
End Sub

Private Sub ComboBox1_LostFocus()
MsgBox "Changed to:" & ComboBox1.Value
End Sub

This is not working on Slide 2: 这不适用于幻灯片2:

Private Sub TextBox1_Change()
TextBox1.Value = "Change: " & 
ActivePresentation.Slides(1).Shapes("ComboBox1").OLEFormat.Object.Value & 
"is the Type"
End Sub

It sounds like you're most of the way there and just need to know how to pull the selected value from the combobox, so: 听起来您已经走了很多路,只需要知道如何从组合框中提取选定的值即可,所以:

Private Sub ComboBox1_Change()
    MsgBox ActivePresentation.Slides(1).Shapes("ComboBox1").OLEFormat.Object.Value
End Sub

If your intention is to have the ComboBox on slide 1 set the text in TextBox on slide 2, then you need your code to do that. 如果您打算在幻灯片1上设置 ComboBox,则在幻灯片2上设置 TextBox中的文本,那么您需要使用代码来做到这一点。 The TextBox_Change event won't fire unless you manually edit its text (I tested your code, and it works to that effect, but that's probably not what you want). 除非您手动编辑它的文本,否则TextBox_Change事件将不会触发(我测试了代码,并且可以达到这种效果,但这可能不是您想要的)。 So, the problem is that you never assign any value to the TextBox on Slide 2. 因此,问题在于您永远不会为幻灯片2上的TextBox分配任何值。

You can probably remove the TextBox_Change event procedure on Slide 2, I suspect you have used that only for debugging purposes. 您可能可以删除幻灯片2上的TextBox_Change事件过程,我怀疑您仅将其用于调试目的。

Use the ComboBox_Change event to assign the text to the TextBox object on Slide 2. Add this code in your Slide1 module: 使用ComboBox_Change事件将文本分配给幻灯片2上的TextBox对象。在您的Slide1模块中添加以下代码:

Private Sub ComboBox1_Change()
    ActivePresentation.Slides(2).Shapes("TextBox1").OLEFormat.Object.Value = Me.ComboBox1.Value
End Sub

To apply to all subsequent slides: 应用于所有后续幻灯片:

Private Sub ComboBox1_Change()
    Call UpdateOtherSlides()
End Sub
Private Sub UpdateOtherSlides()
    Dim s as Long
    Dim text as String
    Text = Me.ComboBox1.Value
    For s = 2 to ActivePresentation.Slides.Count
        On Error Resume Next 'In case no "TextBox1" exists on the slide
        ActivePresentation.Slides(s).Shapes("TextBox1").OLEFormat.Object.Value = text
    Next

End Sub

NB : Option Explicit is a way to force you to declare all variables. 注意Option Explicit是一种强制您声明所有变量的方法。 It won't compile string literal names against the Shapes of any worksheet, but it will prevent you from using a variable name like ComboBox1 in a slide module where no such object exists. 它不会针对任何工作表的Shapes编译字符串文字名称,但是它将阻止您在不存在此类对象的幻灯片模块中使用像ComboBox1这样的变量名称。

暂无
暂无

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

相关问题 Powerpoint幻灯片:如何将我在一张幻灯片上的组合框和文本框控件复制到另一张相同演示文稿的幻灯片上? - Powerpoint slides: how to copy my combobox and textbox controls on one slide to a another slide, same presentation? PowerPoint幻灯片可显示MySql数据库中的数据? 怎么样? - PowerPoint slide to display data from MySql database? How? 将特定幻灯片添加到幻灯片的powerpoint数组 - add a specific slide to a powerpoint array of slides 如何将模板从另一个 PowerPoint 复制到幻灯片中? - How to copy template into slide from another PowerPoint? Powerpoint VBA 从当前幻灯片或所有幻灯片中的文本框和形状中删除文本 - Powerpoint VBA Delete Text from TextBoxes and Shapes in Current Slide or All Slides 如何从Excel向PowerPoint幻灯片添加图片 - How to add a picture to a powerpoint slide from excel VBA / Powerpoint:如何列出哪些幻灯片属于任何现有幻灯片母版? - VBA/Powerpoint: How can I list which slides belong to any existing slide masters? 如何将包含多张幻灯片的 PowerPoint 文件拆分为每个包含 1 张幻灯片的多个文件? - How can I split a PowerPoint file with multiple slides into multiple files of 1 slide each? 如何使用 vba 将幻灯片中的 PowerPoint 文字传递到 txt? - How to pass PowerPoint words from slides to a txt with vba? 在powerpoint中显示幻灯片进度百分比 - Display slide progress percentage in powerpoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM