Populating Listbox on workbook open

Spoony

New Member
Joined
Jun 12, 2009
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I'm trying to populate a listbox that I have put on my sheet.

Using the Workbook_Open:

with ListBox1
.additem "AAA"
.additem "BBB"
end with

however, it gives me a Run-time error 91

"Object variable or with block variable not set"

Can anyone please give me some clues as to what I need to do.

Many thanks

Steve
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try like this

Code:
With ActiveSheet.ListBoxes("List Box 1")
    .AddItem "AAA"
    .AddItem "BBB"
End With
 
Upvote 0
Thanks Peter

It didn't work, I even took out the spacing in the name to see if it would make a difference


Private Sub Workbook_Open()

With ActiveSheet.ListBoxes("ListBox1")
.Clear
.AddItem "Horizontal"
.AddItem "Manufacturing"
.AddItem "AEC"
.AddItem "Retail"
End With

End Sub
 
Upvote 0
Where is this list box from? Is it a Forms list box or a Controls (ActiveX) list box?
 
Upvote 0
In that case

Code:
With ActiveSheet.OLEObjects("ListBox1").Object
    .AddItem "AAA"
    .AddItem "BBB"
End With
 
Upvote 0
Just a note: I tried adding some dynamically to an existing listbox, but the .additem doesn't work if you have ListFillRange set - you get a permissions error.

BTW, does anybody know how to initialize this to no selection in workbook to force the user to make one? Is that possible in a ole listbox?
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top