Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel VBA Combobox object syntax help

Posted on 2011-03-14
4
Medium Priority
?
502 Views
Last Modified: 2012-05-11
I have a Class Module that needs to fill a combobox. It works fine when I hard code the combobox like
Dim cmbCombo as ComboBox
Set cmbCombo = ActiveSheet.cmbMyCombo1

Now I want to pass the string "cmbMyCombo1" to the object (from this class) so I can address any specified combo on the sheet. How do I modify the above?

I tried ... and didn't work
Set cmbCombo = ActiveSheet.Shapes.Range(Array(m_comboname))
(m_comboname is the local variable holding "cmbMyCombo1" and I got that syntax from the macro recorder, which worked for .Left for example)

Thanks.
0
Comment
Question by:hindersaliva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 35130223
Try:
Set cmbCombo = ActiveSheet.OLEObjects(m_comboname).Object

Open in new window

0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35130239
Or:
   Set cbo = CallByName(ActiveSheet, m_comboname, VbGet)

Open in new window

0
 

Author Comment

by:hindersaliva
ID: 35130243
Wow Rory! Masterful!!!!
Thanks. Exactly right.
0
 

Author Comment

by:hindersaliva
ID: 35130352
The CallByName works also.
Never knew that one!
Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question