VB.NET: how to populate combobox from VBA macro

andy7789
andy7789 used Ask the Experts™
on
Hi X-perts,

I have a form designed in VB.NET, which I need to populate from VBA Excel.

1) I open the form and initialize its object from VBA
2) Adding an item to ComboBox2 (of the VB.NET form)

VBForm.ComboBox2.Items.Add(f.Name)

3) VBA editor translates its to - adding a space before(f.Name)

.ComboBox2.Items.Add (f.Name)

4) It returns an error Object required

The problem is that

.ComboBox2.Items.Add(f.Name)
is a VB.NET syntax, which foreign for VBA, that's why it ads a space

How can I fix this? Of course, i can call a special macro inside VB.NET, but it would make it more difficult

Any ideas?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I just have a comment. A better way to do it is what you suggest of making a function in VB.NET and just calling that function from VBA. You can even make the function accept parameters, and you pass anything you need from the VBA.

NY

Author

Commented:
Yes, you are right. This is what I have figured out already. The problem of VBA and VB.NET different syntax pops out everywhere, not only in that combobox example
You could take advantage of the fact that you are going to be changing some code, to migrate all of your code to VB.NET and use the Excel Interop classes to interact with whatever you need of Excel. I find that much cleaner.

Thanks for the grade,
NY

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial