|
-
May 30th, 2006, 04:23 PM
#1
Thread Starter
New Member
so simple, yet so difficult (checkbox selection)
Hey guys,
Im pretty decent with vba. I'm having a problem.
Im trying to run a FOR loop and go through my checkboxes which are named
"graph1" ,"graph2","graph3"...
basically I need to be able to call the checkbox from the worksheet, they arent in a form.
I've been trying activesheet.shapes("graph1").selection and thats not working
Ive also tried sheet1.checkboxes and sheet1.checkbox. Its really stumped me.
I know I need to be able to take "graph" & i and put that into the checkbox call. What should I do?
-
May 30th, 2006, 04:58 PM
#2
Re: so simple, yet so difficult (checkbox selection)
G'Day gotskill10, Welcome to the Forum 
Here is a simple NON ROBUST way - get you going at least (for Excel).
VB Code:
Dim objShp As Shape
For Each objShp In ActiveSheet.Shapes
If InStr(objShp.Name, "graph") <> 0 Then
'CheckBox
MsgBox objShp.Name
End If
Next
Or
VB Code:
Dim objShp As Shape
For Each objShp In ActiveSheet.Shapes
If Left$(LCase(objShp.Name), 5) = "graph" Then
'CheckBox
MsgBox objShp.Name
End If
Next
I will post back a better solution soon
Last edited by Bruce Fox; May 30th, 2006 at 08:33 PM.
-
May 30th, 2006, 06:17 PM
#3
Thread Starter
New Member
Re: so simple, yet so difficult (checkbox selection)
thanks for the help. I tried out your solution. I was able to get it to cycle through those checkboxes, however, how can i reference the checkboxes value (either true or false)?
i tried sheet1.objshp
or sheet1.checkbox(objshp.name)
How else can I do this?
-
May 30th, 2006, 06:30 PM
#4
Re: so simple, yet so difficult (checkbox selection)
-
May 30th, 2006, 06:44 PM
#5
Thread Starter
New Member
Re: so simple, yet so difficult (checkbox selection)
i tried that as well, it doesnt work, there is no value to the shapes library
-
May 30th, 2006, 08:39 PM
#6
Re: so simple, yet so difficult (checkbox selection)
Here you go... (note: I changed the Variable Name to better reflect Hungarian Notation - now shpObj):
VB Code:
Dim shpObj As Shape
For Each shpObj In ActiveSheet.Shapes
If InStr(shpObj.Name, "graph") <> 0 Then
'CheckBox
MsgBox shpObj.Name
[b]MsgBox OLEObjects(shpObj.Name).Object.Value[/b]
End If
Next
Or
VB Code:
Dim shpObj As Shape
For Each shpObj In ActiveSheet.Shapes
If Left$(LCase(shpObj.Name), 5) = "graph" Then
'CheckBox
MsgBox shpObj.Name
[b]MsgBox OLEObjects(shpObj.Name).Object.Value[/b]
End If
Next
And using the OLEObjects Collectio (opposed to Shapes):
VB Code:
Dim oleObj As OLEObject
For Each oleObj In OLEObjects
If Left$(LCase(oleObj.Name), 5) = "graph" Then
'CheckBox
MsgBox oleObj.Name
MsgBox OLEObjects(oleObj.Name).Object.Value
End If
Next
Last edited by Bruce Fox; May 30th, 2006 at 08:46 PM.
-
May 31st, 2006, 10:25 AM
#7
Thread Starter
New Member
Re: so simple, yet so difficult (checkbox selection)
 Originally Posted by Bruce Fox
Here you go... (note: I changed the Variable Name to better reflect Hungarian Notation - now shpObj):
VB Code:
Dim shpObj As Shape
For Each shpObj In ActiveSheet.Shapes
If InStr(shpObj.Name, "graph") <> 0 Then
'CheckBox
MsgBox shpObj.Name
[b]MsgBox OLEObjects(shpObj.Name).Object.Value[/b]
End If
Next
Or
VB Code:
Dim shpObj As Shape
For Each shpObj In ActiveSheet.Shapes
If Left$(LCase(shpObj.Name), 5) = "graph" Then
'CheckBox
MsgBox shpObj.Name
[b]MsgBox OLEObjects(shpObj.Name).Object.Value[/b]
End If
Next
And using the OLEObjects Collectio (opposed to Shapes):
VB Code:
Dim oleObj As OLEObject
For Each oleObj In OLEObjects
If Left$(LCase(oleObj.Name), 5) = "graph" Then
'CheckBox
MsgBox oleObj.Name
MsgBox OLEObjects(oleObj.Name).Object.Value
End If
Next
I tried this, none of them work, for MsgBox OLEObjects(shpObj.Name).Object.Value, there is no object in the oleobjects, and i looked at the oleobjects library, there is no way to get a value.
With your last code:
For Each oleObj In OLEObjects
It gives me an error here, even with the dim oleobj as oleobject.
Are there any other solutions?
-
May 31st, 2006, 10:27 AM
#8
Re: so simple, yet so difficult (checkbox selection)
What error did it give you?
-
May 31st, 2006, 10:35 AM
#9
Thread Starter
New Member
Re: so simple, yet so difficult (checkbox selection)
for MsgBox OLEObjects(shpObj.Name).Object.Value
it says "sub or function not defined," but thats because of the .object.value, if you put OLEObjects(shpObj.Name).select, it works, but doesn't let me do selection.value.
on
Dim oleObj As OLEObject
For Each oleObj In OLEObjects
If Left$(LCase(oleObj.Name), 5) = "graph" Then
'CheckBox
MsgBox oleObj.Name
MsgBox OLEObjects(oleObj.Name).Object.Value
End If
Next
I get an object required error on For Each oleObj In OLEObjects, I have the Dim oleObj As OLEObject in there.
-
May 31st, 2006, 03:55 PM
#10
Re: so simple, yet so difficult (checkbox selection)
What version of Excel are you running? I successfully tested on Office 2003.
-
May 31st, 2006, 04:34 PM
#11
Thread Starter
New Member
Re: so simple, yet so difficult (checkbox selection)
im using excel 2003, sp2 which exact code did you try?
-
May 31st, 2006, 09:13 PM
#12
Re: so simple, yet so difficult (checkbox selection)
All..... 
I re test.
EDIT: Works....
Do you get an intellisense of OLEObjects when you Dim x As [[[OLEO.....]]]
Last edited by Bruce Fox; May 31st, 2006 at 09:19 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|