[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Set the value selected for an ActiveX ComboBox using VBA

Posted on 2013-05-22
5
Medium Priority
?
6,130 Views
Last Modified: 2013-05-30
I am trying to set the value selected for an ActiveX Control Box using VBA to the first item in the list or blank. When recording the macro no code is produced for the action.
0
Comment
Question by:tjd71
  • 3
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 2000 total points
ID: 39190128
Hi,

Set the ListIndex property of the ComboBox to 0 (zero).

For example:
Option Explicit
Public Sub Create_ComboBox1()

  ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
                             Link:=False, _
                             DisplayAsIcon:=False, _
                             Left:=50, _
                             Top:=50, _
                             Width:=100, _
                             Height:=18).Select

  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "First"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Second"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Third"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Fourth"
  ActiveSheet.OLEObjects("ComboBox1").Object.AddItem "Fifth"
  
  ActiveSheet.OLEObjects("ComboBox1").Object.ListIndex = 0&     ' Select the first item
  
End Sub

Open in new window


BFN,

fp.
0
 

Author Comment

by:tjd71
ID: 39198295
Thanks FP, I am away from the office until Thursday and will try it then.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39198635
OK.  Thanks for letting me know.
0
 

Author Closing Comment

by:tjd71
ID: 39206572
Hi Fp,

Thanks :) Too easy once you know how.

Cheers
tjd71
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39206908
:) You're welcome.

Sometimes it is the simplest of things that become the most difficult to discover!

Good luck with the rest of your project.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

834 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