Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Manipulating a checkbox by name dynamically

I have a bunch of checkboxes (not an array) that have
names like: rep1_cb, rep2_cb, rep3_cb, etc. I need to
iterate through all of them and change their captions.

My code looks something like this:

Dim counter as integer
counter = 1
Do Until...
Sheet1.OLEObjects("rep" & counter & "_cb").Object.???
counter = counter + 1
Loop


I don't know the syntax here for this. Is "Sheet1" the
correct thing to use altogether?

Thanks!
Eliezer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Manipulating a checkbox by name dynamically

In your example, Sheet1 would be the codename of the worksheet.

When you're in the VBE, hit ctrl-r to see the project explorer for your project.
Expand it to see the Microsoft Excel Objects.

You'll see items like:
Sheet1 (MySheetName)

The name to the left is the code name. The name in parentheses is the name you
can see on the worksheet tab.

And you could have used:
worksheets("mySheetName").oleobjects.....
if you knew that the worksheet name wouldn't change.

If I knew how many checkboxes there were, I'd do something like:

Option Explicit
Sub testme()

Dim iCtr As Long

For iCtr = 1 To 4
Sheet1.OLEObjects("rep" & iCtr & "cb").Object.Caption = "Hi_" & iCtr
Next iCtr

End Sub

If I wanted to get them all, but didn't know how many, I could get them this
way:

Sub testme2()

Dim OLEobj As OLEObject

For Each OLEobj In Sheet1.OLEObjects
If TypeOf OLEobj.Object Is MSForms.CheckBox Then
OLEobj.Object.Caption = "Hi_there"
End If
Next OLEobj

End Sub

Eliezer wrote:

I have a bunch of checkboxes (not an array) that have
names like: rep1_cb, rep2_cb, rep3_cb, etc. I need to
iterate through all of them and change their captions.

My code looks something like this:

Dim counter as integer
counter = 1
Do Until...
Sheet1.OLEObjects("rep" & counter & "_cb").Object.???
counter = counter + 1
Loop

I don't know the syntax here for this. Is "Sheet1" the
correct thing to use altogether?

Thanks!
Eliezer


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have Checkbox A uncheck with checked Checkbox B Texas Aggie Excel Discussion (Misc queries) 3 July 20th 07 10:58 PM
manipulating dates ghostinhawaii Excel Worksheet Functions 2 March 24th 07 05:16 AM
Manipulating shapes thePriest Excel Discussion (Misc queries) 0 April 20th 05 06:41 PM
Manipulating DOS from VBA Dave Peterson[_3_] Excel Programming 0 October 17th 03 01:46 AM
manipulating pictures with VBA sec12205 Excel Programming 2 August 28th 03 04:36 PM


All times are GMT +1. The time now is 04:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"