Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help:Programmatically Adding Checkboxes with Captions

Programmatically Adding Checkboxes with Captions

Here is what I am trying to accomplish:

I have "Sheet1" which the user has the ability to select options
etc.

Once they are done, a vbscript is triggered:
1) creates a new worksheet.
2) Adds a dynamic number of checkboxes(depends on user interaction from
sheet1)
This is where I'm having trouble. I can use a loop and create as
many checkboxes as needed, but I can't add a caption to them. Here
is the code I'm using:

'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

If dePartment = "7" Then
sopSteps = 46
Else
sopSteps = 47
End If

ThisWorkbook.Sheets.Add

For myCounter = 1 To sopSteps

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Link:=False,
_
DisplayAsIcon:=False, Left:=10, Top:=spaceBetweenCheckboxes,
Width:=108, Height:= _
19.5).Select

spaceBetweenCheckboxes = spaceBetweenCheckboxes + 25

Next myCounter

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^

The checkboxes are created and added to the sheet just fine, but if I
try to add 'Caption:="test"', for example, I get an error
telling me this is not valid. (by the way I am going to use an array
to assign the captions - but this is an example to keep it simple).

Is there a parameter for this method that lets me add a caption? Any
ideas or other ways to add a checkbox programmatically that will let me
set the caption?

Thanks in advance
Josh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help:Programmatically Adding Checkboxes with Captions

This skinnied down version worked ok for me:

Option Explicit
Sub testme2()

Dim sopSteps As Long
Dim spaceBetweenCheckboxes As Double
Dim OLEObj As OLEObject
Dim myCounter As Long

sopSteps = 5
spaceBetweenCheckboxes = 14.4

ThisWorkbook.Sheets.Add

For myCounter = 1 To sopSteps

Set OLEObj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=10, _
Top:=spaceBetweenCheckboxes, _
Width:=108, Height:=19.5)

OLEObj.Object.Caption = "Hi there"

spaceBetweenCheckboxes = spaceBetweenCheckboxes + 25

Next myCounter
End Sub



wrote:

Programmatically Adding Checkboxes with Captions

Here is what I am trying to accomplish:

I have "Sheet1" which the user has the ability to select options
etc.

Once they are done, a vbscript is triggered:
1) creates a new worksheet.
2) Adds a dynamic number of checkboxes(depends on user interaction from
sheet1)
This is where I'm having trouble. I can use a loop and create as
many checkboxes as needed, but I can't add a caption to them. Here
is the code I'm using:

'VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

If dePartment = "7" Then
sopSteps = 46
Else
sopSteps = 47
End If

ThisWorkbook.Sheets.Add

For myCounter = 1 To sopSteps

ActiveSheet.OLEObjects.Add(ClassType:="Forms.Check Box.1", Link:=False,
_
DisplayAsIcon:=False, Left:=10, Top:=spaceBetweenCheckboxes,
Width:=108, Height:= _
19.5).Select

spaceBetweenCheckboxes = spaceBetweenCheckboxes + 25

Next myCounter

'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^

The checkboxes are created and added to the sheet just fine, but if I
try to add 'Caption:="test"', for example, I get an error
telling me this is not valid. (by the way I am going to use an array
to assign the captions - but this is an example to keep it simple).

Is there a parameter for this method that lets me add a caption? Any
ideas or other ways to add a checkbox programmatically that will let me
set the caption?

Thanks in advance
Josh


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Help:Programmatically Adding Checkboxes with Captions

Thanks a lot Dave! I haven't done much scripting in Excel and I'm not
too familiar with OLEObjects. I was able to implement the array and it
works like a champ. Thanks again,

Josh

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
Adding checkboxes programmatically to a worksheet Stef Excel Programming 2 February 1st 05 03:53 PM
"Reading" Excel VBA checkboxes and their captions Eliezer Excel Programming 5 September 9th 04 02:30 AM
Removing Checkboxes Programmatically Mark D'Agosta Excel Programming 4 October 21st 03 03:57 PM
Adding Checkboxes Programmatically Mark D'Agosta Excel Programming 1 October 8th 03 03:20 AM
Adding Checkboxes Wes[_3_] Excel Programming 2 July 31st 03 11:27 PM


All times are GMT +1. The time now is 12:55 PM.

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"