Excel - insert a control using VB

I create a work sheet at run time, inserting text and formulae, but I do not know how to insert a combo box into a cell and fill it with values for the user to select.

TIA

John, UK
JohnHindAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SubhasundarCommented:
dear JohnHind,

Just try out this following piece of code:
Make these declarations in a module:
Dim db As Object
Dim wb As Object
Dim ws As Object

Then write the following piece of code( which I have inserted in the form load event):

Private Sub Form_Load()

Set db = CreateObject("Excel.Application")
db.Visible = True

Set wb = db.Workbooks.Add(1)
Set ws = wb.Worksheets.Add
ws.Activate

ws.dropdowns.Add(96.75, 115.5, 47.25, 12).Select


End Sub


Hope it works.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SubhasundarCommented:
I have modified the code a bit. It is like this:

Private Sub Form_Load()

Set db = CreateObject("Excel.Application")
db.Visible = True

Set wb = db.Workbooks.Add(1)
Set ws = wb.Worksheets.Add
ws.Activate
Dim cb As Object
Set cb = ws.dropdowns.Add(96.75, 115.5, 47.25, 12)
'With selection
   cb.AddItem "subha", 1 ' first value to add
'End With
   

End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.