General discussion

Locked

Naming Objects in VBA

By rwint ·
I have XP and Office 2003. In powerpoint I have added a textbox object to numerous slides which I wish to access in VBA (ex. msgbox Slide5.Team1.Value displays the content of a textbox called "Team1" on a slide named "slide5"). The Team1 textbox exists on all slides. How can I substitute a variable name for "slide5" so I can programmatically access the textbox value on any slide.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by blamberson In reply to Naming Objects in VBA

'add this code
Dim strSlide as string

strSlide = Inputbox "enter the Slide number. eg Slide5'"
msgbox Slide5." & strSlide & ".Team1.Value"

Collapse -

by rwint In reply to

Did you try this? It did not work for me (two reasons)
1. There are a couple of syntax errors (I'm assuming) due to missing "()" around the inputbox command and the missing quote in front of Slide5" (I fixed this but the code still doesn't work)
2. "Slide5" (this is what I need to replace with a variable) is a powerpoint object. "Team1" is a textbox directly on the slide (not on a VB form). This control was added using the PowerPoint "Control Toolbox" icon on the "Visual Basic" toolbar (not using the powerpoint "Insert", "TextBox" menu options). I need the textbox to allow data entry during the slideshow which I am going to process further in the VB logic.

Collapse -

by blamberson In reply to Naming Objects in VBA

Sorry, I did not test it.
try this

Dim strSlide as string

strSlide = Inputbox ("enter the Slide number. eg Slide5")
msgbox Team1." & strSlide & ".Team1.Value"

Collapse -

by rwint In reply to

Let me try a different approach in explaining the issue.
1. I have a presentation slide full of shapes that simulates the Family Feud game show. Easch slide represents a different Family feud question (i.e. multiple slides).
2. Each Family Feud game slide has a VB text box so that during the slideshow the user can enter an answer.
3. Using VB code I check the users entries and reveal Family Feud answers until all are exposed.
4. I then move on to the next slide which starts the next Family Feud round.
5. The VBA code for each slide is the same, each slide with its own textbox (called Team1)
6. To read the textbox value into the VBA code I need to use the slide name (i.e. msgbox Slide5.Team1.Value)
7. How do I modify the Slide5 reference for subsequent slides.
8. Instead of returning me the textbox value/content, your solution returns "Team1.slide5.Team1.Value"

Collapse -

by rwint In reply to Naming Objects in VBA

I got my answer from another source (thanks for trying)

Sub xxSurveySays()
Dim intI As Integer
Dim intJ As Integer
Dim objTxt As Object
For intI = 1 To Presentations(1).Slides.Count
If SlideShowWindows(1).View.Slide.Name = Presentations(1).Slides(intI).Name Then
For intJ = 1 To Presentations(1).Slides(intI).Shapes.Count
If Presentations(1).Slides(intI).Shapes(intJ).Type = msoOLEControlObject Then
Set objTxt = Presentations(1).Slides(intI).Shapes(intJ).OLEFormat.Object
If Mid$(objTxt.Name, 1, 4) = "Team" Then
MsgBox objTxt.Name + " = " + objTxt.Text
End If
Set objTxt = Nothing
End If
Next intJ
End If
Next intI
End Sub

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums