Calling Workbook_Open() marco using a button.

bposaner

Board Regular
Joined
May 28, 2002
Messages
74
I got a Private Sub Workbook_Open() marco which runs fine and refreshes various listboxes.
However once opened I need to refresh various sheets, linked to access databases. This works fine, but then the list boxes could be wrong. So i need to rerun the Workbook_Open macro.
What i'm trying to do is add a button which will run the "Private Sub Workbook_Open()" macro.
The only way I can run the macro is open VBA, and manually run the macro.

I tried createing a macro and calling "Workbook_Open()" but it wasn't any good.

So your help would be great.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
The Workbook_Open event cannot be called from anywhere else other than by opening the Workbook as it is a Private Event.

What I suggest you do is put your code in a Module and call it something like:
Sub OpenMacro()

Then under the Workbook_Open event, call this macro, i.e:
Code:
Private Sub Workbook_Open()
OpenMacro
End Sub

You can then also call that macro from a command button, i.e:
Code:
Private Sub CommandButton_Click()
OpenMacro
End Sub
 
Upvote 0
I had thought of that.
Just means more work to change the several workbooks I use this for :(
Was hoping for a simple answer.
Thanks.
 
Upvote 0
Why not just remove the Private?

Then you can use something like this.
Code:
ThisWorkbook.Workbook_Open
 
Upvote 0
So will the macro still automatically run when the workbook opens?
And I will also be able to call it from a button?
 
Upvote 0
Yes it will, well it did when I tested it.:)

The only disadvantage is that the workbook Open event will now be listed when you goto Tools>Macros...
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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