PDA

View Full Version : Creating combobox



arm
10-15-2008, 10:39 PM
Hi,

In Word, is it possible to create object like combobox or button using VBA script (if it is not existing on the document)? If it is possible, so how to create it?

Thanks!

Regards,
arm

CreganTur
10-16-2008, 05:10 AM
Welcome to the forum- it's always good to see new members.

It depends on where you want to put the combobox. If you're using a UserForm, then you just need to choose combobox from the toolbox when you're creating your UserForm.

If you want to create a combobox on your document, then you need to bring up the Control Toolbox toolbar (View -> Toolbars -> Control Toolbox).

Check Word help for specific info on loading data into your combobox.

fumei
10-20-2008, 07:27 AM
"In Word, is it possible to create object like combobox or button using VBA script (if it is not existing on the document)? If it is possible, so how to create it?"

Yes. Declare an object, and then Set it. You do not state what type of combobox - it could be a formfield dropdown, or an ActiveX combobox...which? However, here is the code for an ActiveX combobox. it is placed at the Selection. If you do NOT want it at the Selection, then you would, of course, have to adjust it.

Dim oYadda As InlineShape
Set oYadda = Selection.InlineShapes.AddOLEControl _
(ClassType:="Forms.ComboBox.1")


Note also, that you can do things with that object, but some things are not intuitive, and also many things are NOT available with Intellisense. In other words, you can put the dot, but nothing comes up as choices. The big one is OLEFormat.Object, as in:

Dim oYadda As InlineShape
Set oYadda = Selection.InlineShapes.AddOLEControl _
(ClassType:="Forms.ComboBox.1")
oYadda.OLEFormat.Object.various other properties