Another PowerPoint VBA Question

C

Chris

Hi to all:

I am trying to clean up code in initializing my variables. I would like to
create a loop to handle the resetting of all variables to False. The
variables are SlideXX.(a,b,c, or d). I have tried defining Var1 in the code
below many different ways. The code I am trying to get to work is:

Sub SlideInit()

For i = 70 To 90
If i = 83 Or i = 89 Then GoTo Jmp 'I have no variables on slides 83 or 89
If i >= 85 And i <= 87 Then GoTo Jmp ' I have no variables on slides 85-87
Var1 = "Slide" & CStr(i)
Response = MsgBox(Var1, vbOKOnly, "test") 'Used to see the value of Var1
Var1.a = False
Var1.b = False
Var1.c = False
Var1.d = False
Jmp:
Next i
End Sub

Thanks to all who are able to help.
 
B

Bill Dilworth

Hi Chris,

You are obviously used to writing code in a slightly more advanced version
of something. Variable names can not be variables in VBA. However


You can create 4 single dimensioned Boolean arrays ....
Dim booResponseA(90) as Boolean
Dim booResponseB(90) as Boolean
Dim booResponseC(90) as Boolean
Dim booResponseD(90) as Boolean


.... or a single two-dimensional Boolean array.
Dim booResponse(90,4) as Boolean


Then to reset them, just
For i = 1 To 90
For j = 1 To 4
booResponse(i, j) = False
Next j
Next i


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

Chris

Steve:

My code is in a module not slides. The optionbutton groups are named Slide
80, Slide81, etc. and the optionbuttons on each slide are named (a,b,c,d).
This is an extremely efficient way to name the group, keep track of the
variables, and makes it easy to write an evaluation code for testing. The
more standard the naming conventions, the easier it is to use over and over.
 
C

Chirag

Hi Chris,

See if you can use the following code:

---
Sub ClearOptionButtonsOnSlide(ByVal Pres As Presentation, _
ByVal SlideName As String)

Dim Sld As Slide
Dim Shp As Shape

Set Sld = Pres.Slides(SlideName)
If Not (Sld Is Nothing) Then
For Each Shp In Sld.Shapes
If Shp.Type = msoOLEControlObject Then
If Shp.OLEFormat.ProgID = "Forms.OptionButton.1" Then
Shp.OLEFormat.Object.Value = False
End If
End If
Next
End If
End Sub
---

In your SlideInit() sub, after you have proper value set in Var1, call this
above function as demonstrated here:

---
Sub SlideInit()
...
ClearOptionButtonsOnSlide ActivePresentation, Var1
...
End Sub
---

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
C

Chris

Hi Chirag,

This solution worked. Thank you for your time and assistance with this issue.

Chris
 
Top