Macro (attached to ActiveX List Box) running on open?

Sarah52181

New Member
Joined
Mar 7, 2012
Messages
19
I'm afraid I may be in a bit over my head here. I have a spreadsheet with multiple brands on it, and I've added an ActiveX listbox that allows you to select which brands you want to view (Brand A, Brand B, or "all brands"). It works great, however it appears that my macros are running on workbook open.

None of my macros (and there are several) have the "Workbook_Open" code in them, so I'm not sure what's going on?

It really doesn't do any harm, except that someone opening the workbook has to watch excel flash and blink and go through all of these steps/calculations evertime you open it. :eeek:

Has anyone seen this before?

I thought Excel might be treating the "workbook open" as me making a selection on one of my listboxes (even if it was already selected) and thus running that macro, but the same thing happens even if I save the workook to display a sheet that doesn't have a listbox.

ETA: From what I've read, activeX controls are always autoloaded when a workbook containing them opens. That's unfortunate. Am I out of luck here for a speedy workbook open?
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Thanks! I started with a form control, but I couldn't figure out how to assign a different macro to each selection contained within the listbox. It was relatively easy with an activeX control.

Is there a way to do the same thing for a form control?

The code I used for ActiveX was:

Code:
Private Sub ListBox1_select()
Select Case ListBox1.ListIndex
Case 0: targetunhideall
Case 1: targetm
Case 2: targeth
End Select
End Sub
 
Upvote 0
ooooo - I could just use (form control) option buttons and assign a macro to each button. With a little clever formatting it will ultimately look just like the activeX listbox I started with only it won't take forever to open. Thanks!
 
Upvote 0
Similar code for the macro:
Code:
Private Sub ListBox1_select()
Dim lb as Listbox
Set lb = activesheet.listboxes(application.caller)
Select Case lb.ListIndex
Case 0: targetunhideall
Case 1: targetm
Case 2: targeth
End Select
End Sub
 
Upvote 0
one way to get selection from a form control list box:

Code:
Sub example()
    Dim ws As Worksheet
    Dim lbName As String
    
    Set ws = ActiveSheet
    lbName = "List Box 1"
    
    MsgBox ws.Shapes(lbName).ControlFormat.List(ws.Shapes(lbName).ControlFormat.ListIndex)
End Sub

Assign the above code to the list box and it will display a message whenever you click on "List Box 1", which is the default name for the first list box added to the sheet.

Instead of the message box you can assign it to a variable and use it in your other code.
 
Upvote 0
Thanks guys! Great suggestions AND it's prompted me to come up with my own (at least temporarily) acceptable solution, which is also pretty great.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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