HELP!!!!! PowerPoint VBA OptionButton Reference

G

Guest

I need to check if an option button is selected (True) and increment a
counter if it is True. My problem is referring to the slide object option
button. PowerPoint does not seem to want to allow a variable in the object
name. I have tried using the variable as well as "Slide52.OptionButton & i"

My code is:

Dim i, Qvid, OptBtn, Result

For i = 3 To 12 Step 3
OptBtn = "Slide52.OptionButton" & i
If OptBtn = True Then Qvid = Qvid + 1
 
D

David M. Marcovitz

I don't think you can do what you want in the way you want. You should
note that an OptionButton is an object, so you need Set to assign it to a
variable as in:

Set OptBtn = Slide52.OptionButton3

However, you don't want the OptionButton itself, just the value of the
option button, so you might want:

Dim OptBtn as Boolean

OptBtn = Slide52.OptionButton3.Value

However, this doesn't get you the nice variable thing you want. Right
now, everything that I can think of is just going to make this harder.

--David

--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
 
B

Bill Dilworth

Unlike VB6, Option buttons in VBA can not be set as an array.

One option is to tag the option button object and run thru all the objects
on the slide to look for the buttons.

For Each oShp In ActivePresentation.Slides(52).Shapes
If Left(oShp.Name, 12) = "OptionButton" Then
'Your stuff
End If
Next oShp

--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.
http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
yahoo2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com
..
 
S

Steve Rindsberg

Unlike VB6, Option buttons in VBA can not be set as an array.

One option is to tag the option button object and run thru all the objects
on the slide to look for the buttons.

For Each oShp In ActivePresentation.Slides(52).Shapes
If Left(oShp.Name, 12) = "OptionButton" Then
'Your stuff
End If
Next oShp

Or:

Function IsSelected(oSld as Slide, sOButtonName as String) as Boolean
' Pass the slide as a slide object and the name of the option button you want
' as a string

IsSelected = oSld.Shapes(sOButtonName).OLEFormat.Object.Value

End Function

So you'd do:

If IsSelected(ActivePresentation.Slides(1), _
"OptionButton" & Cstr(iButtonNumber)) Then
MsgBox ("The button is selected")
Else
MsgBox ("The button is NOT selected")
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top