Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Looping through all comboboxes in workbook and setting values with .additem

Hi Folks
I want to loop through all comboboxes when my workbook opens and set
the values for them. I can loop through them using the oleobjects
collection but that doesn't support the .additem method. I can also
loop through the shapes collection and access them, but again can't
use .additem I am going to have about 100 combo boxes spread over many
sheets with the same values. Being able to loop through and set the
values will save a ton of time. I've tried lots of help resources and
headscratching and still can't figure this one out.
Thanks
Mike

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Looping through all comboboxes in workbook and setting values with.additem

You should be able to use .additem.

This worked ok for me:

Option Explicit
Sub auto_open()

Dim OLEObj As OLEObject
Dim wks As Worksheet
Dim iCtr As Long

For Each wks In ThisWorkbook.Worksheets
For Each OLEObj In wks.OLEObjects
If TypeOf OLEObj.Object Is MSForms.ComboBox Then
For iCtr = 1 To 10
OLEObj.Object.AddItem "A" & iCtr
Next iCtr
End If
Next OLEObj
Next wks

End Sub


Mike wrote:

Hi Folks
I want to loop through all comboboxes when my workbook opens and set
the values for them. I can loop through them using the oleobjects
collection but that doesn't support the .additem method. I can also
loop through the shapes collection and access them, but again can't
use .additem I am going to have about 100 combo boxes spread over many
sheets with the same values. Being able to loop through and set the
values will save a ton of time. I've tried lots of help resources and
headscratching and still can't figure this one out.
Thanks
Mike


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Looping through all comboboxes in workbook and setting values with .additem

Mike,

If the Ole Objects does not work, try difining the comboboxes as dropdowns.
Use the following code:

Sub FillDropDowns()

Dim ddDropDown as DropDown
Dim wsSheet As Worksheet
Dim intCount as Integer

For Each wsSheet in ThisWorkbook.Worksheets
For Each ddDropDown in wsSheet.DropDowns
For intCount=1 to maxNumInputs
ddDropDown.AddItem <item
Next intCount
Next ddDropDown
Next wsSheet

End Sub


"Mike" wrote in message
oups.com...
Hi Folks
I want to loop through all comboboxes when my workbook opens and set
the values for them. I can loop through them using the oleobjects
collection but that doesn't support the .additem method. I can also
loop through the shapes collection and access them, but again can't
use .additem I am going to have about 100 combo boxes spread over many
sheets with the same values. Being able to loop through and set the
values will save a ton of time. I've tried lots of help resources and
headscratching and still can't figure this one out.
Thanks
Mike



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
Worksheets, comboboxes, and integer values Bryan44 Excel Programming 1 March 7th 07 01:07 AM
Using ComboBoxes to get range of values Kirk Lewis Excel Programming 1 September 15th 04 03:08 PM
Looping through ComboBoxes in a worksheet TonyM Excel Programming 2 May 18th 04 01:48 PM
Limiting values in comboboxes. mika.[_2_] Excel Programming 2 November 27th 03 02:02 PM
Setting values in another workbook Ecco Excel Programming 1 July 17th 03 08:15 AM


All times are GMT +1. The time now is 11:52 PM.

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

About Us

"It's about Microsoft Excel"