Share via

ComboBox object variable not set

Anonymous
2012-05-15T23:33:20+00:00

Below is a very simplified code representing my problem.  I am trying to create comboboxes with lists and then separately set the value.  The user can accept the pre-defined value or select from the list.  I don't always want the first item in the list to be the value. 

Option Explicit

Dim MyDropDown As Object

Dim MyList as Variant

Sub test()

     MyList = Array("","apple", "orange", "banana")

     MyDropDown.List = MyList

     MyDropDown.Value = "orange"

End Sub

I get an error that tells me the object variable is not set.

Do I need something like this:

Set MyDropDown = New ???

(I don't see ComboBox as an option) 

I am totally missing something here.

thanks

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2012-05-16T01:18:54+00:00

    Will this work for Word?

    I cannot use

    Dim MyDropDown As OLEObject

    Compile error: User -defined type not defined

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-05-16T00:45:02+00:00

    Was this answer helpful?

    0 comments No comments