0
votes

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.

I have the Slide 1 Combobox working fine. I run the presentation, get focus, pull-down and select my value. It is ComboBox1.

I can't seem to find the trick to reference that Value in future slides. Extremely novice in vb. Not sure I'm using the PowerPoint vb editor properly. Seems my code/values are just limited to the current slide and not future slides.

On slide 2 I have TextBox1 defined. I can get it to take a value with TextBox1.Value = "This is a " & ComboBox1 & " slide." 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.

Is it possible?

Thanks!

Inserting source.

This is working on Slide 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:

Private Sub TextBox1_Change()
TextBox1.Value = "Change: " & 
ActivePresentation.Slides(1).Shapes("ComboBox1").OLEFormat.Object.Value & 
"is the Type"
End Sub
2
If you use Option Explicit in your code modules? If not, do you get an error because ComboBox1 is probably out of scope?David Zemens
I did not use Option Explicit. Seems to be the case. I will try.Cleve SJM
Tried it. Got an "Item ComboBox1 not found in the Shapes collection" using ActivePresentation.Slides(1).Shapes("ComboBox1").OLEFormat.Object.Value as the field. Should I make a new field equal to that before leaving Slide1?Cleve SJM
revise your question to include the code you're trying to use :) makes it easier to assistDavid Zemens
Revised. Thanks!Cleve SJM

2 Answers

1
votes

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
0
votes

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. 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). So, the problem is that you never assign any value to the TextBox on Slide 2.

You can probably remove the TextBox_Change event procedure on Slide 2, I suspect you have used that only for debugging purposes.

Use the ComboBox_Change event to assign the text to the TextBox object on Slide 2. Add this code in your Slide1 module:

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. 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.