Solved

Excel VBA Combobox object syntax help

Posted on 2011-03-14
4
490 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
  • 2
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
Comment Utility
Try:
Set cmbCombo = ActiveSheet.OLEObjects(m_comboname).Object

Open in new window

0
 
LVL 85

Expert Comment

by:Rory Archibald
Comment Utility
Or:
   Set cbo = CallByName(ActiveSheet, m_comboname, VbGet)

Open in new window

0
 

Author Comment

by:hindersaliva
Comment Utility
Wow Rory! Masterful!!!!
Thanks. Exactly right.
0
 

Author Comment

by:hindersaliva
Comment Utility
The CallByName works also.
Never knew that one!
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now