How to create ListBox AND keep reference to that ListBox so I can make it multiselect

N

Novice

Using the "record macro" feature I'm easily able to find that I can create an ActiveX ListBox in my Word Document by
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ListBox.1

But I've been searching high and low (using google) to try to find some way of declaring a variable/object of type ListBox. Most of the VBA examples I found applied to Excel things like
Dim oleObj As OLEObjec
Dim oleObj As ListBo
Dim oleObj As MSForms.ListBo
Dim oleObj As Forms.ListBo
Dim oleObj As Word.OLEForma

All of the above throw run-time errors indicating that the type doesn't exist

However, on my own - using the code completion feature of Microsoft Visual Basic IDE I found this
Dim oleObj As Word.WdOLETyp

This actually doesn't throw an error when I
oleObj = Selection.InlineShapes.AddOLEControl(ClassType:="Forms.ListBox.1"

However, it does throw run-time error when it gets to here
oleObj.MultiSelect = fmMultiSelectMult

At this point I would be satisfied with some extra parameter to this call (if such a parameter exists)
Selection.InlineShapes.AddOLEControl ClassType:="Forms.ListBox.1

such that the control is multi-select - as it doesn't seem possible to create a variable of the OLE type

I should add that I'm using Word 2000

Thanks
Novice
 
N

Novice

It turns out that I was missing the necessary references in order for my project to compile (so I could make use of classes like ListBox)

Here is the code that ended up working
Dim oleObj As ListBo
Set oleObj = Selection.InlineShapes.AddOLEControl(ClassType:="Forms.ListBox.1").OLEFormat.Objec
oleObj.MultiSelect = fmMultiSelectMult

But now I'm a bit concerned that I'm including libraries that I don't need - I basically just went and started clicking next to any library that sounded as if it might give me ActiveX capabilities. After I got the above code working - I started removing libraries - through the process of elimination I got the number of referenced libraries down to this
Visual Basic For Application
Microsoft Word 9.0 Object Librar
OLE Automatio
Microsoft ActiveX Data Objects 2.7 Librar
Microsoft Forms 2.0 Object Librar

Are the above the "right" set of libraries - for use in Word VBA (Word 2000 and VB 6.0)

I think the only two that weren't there to begin with were
Microsoft ActiveX Data Objects 2.7 Librar
Microsoft Forms 2.0 Object Librar

Thanks
Novic

PS Does anyone know of any reference materials that I could have read to start with to save me the pain of going through trial and error to learn what I just learned - i.e. a book/website/etc that discusses the libraries associated with VB and VBA and using the various objects? I would appreciate if this request was taken seriously instead of just posting - www.msdn.com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top