Automatically running a macro

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26
Is there a way to automatically run a macro when a workbook is opened, if certain criteria are met?

(ie IF(cell=x,run macro X,""))

Thanks

Ryan
This message was edited by rmcbreen on 2002-10-24 07:14
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
Name the macro you want to run

Sub AUTO_OPEN()

This will run automatically when workbook is opened - test your criteria - if not met then exit sub.
 

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26
Thanks,

It sounds easy enough. I am new to using macros though, so I will fool around with it.

If I have more than one Macro I want to automatically open, can I use Sub AUTO_OPEN1(), Sub AUTO_OPEN2....etc?
This message was edited by rmcbreen on 2002-10-24 07:18
 

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,123
can't say I have ever tried though the easiest solution would to be create the "other" macros as separate macros (e.g TEST) and then simply call them from the AUTO_OPEN - eg

Sub AUTO_OPEN()

blah blah

TEST
'so this will run the Sub Test() Macro

End Sub
 

rmcbreen

New Member
Joined
Oct 22, 2002
Messages
26

ADVERTISEMENT

You're the best, thanks.
 

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
Welcome rmcbreen,


As another way, you can also use Workbook_Open event.
On menu bar, you can see XL logo icon left of<U>F</U>ile menu.
Right click on the icon, select<U>V</U>iew Code. VBE will appear.
At there , paste code.

If I have more than one Macro I want to automatically open

In this case, you can use Select case method as follows

Assume, trigger is A1 cell of Sheet1, and you have Macro1 to Macro4.<PRE>Private Sub<FONT color=red> Workbook</FONT>_Open()
Select<FONT color=red>Case</FONT>Sheets("Sheet1").[A1].Value<FONT color=red>Case</FONT>1<FONT color=red>Call</FONT> Macro1<FONT color=red>Case</FONT>2<FONT color=red>Call</FONT> Macro2<FONT color=red>Case</FONT>3<FONT color=red>Call</FONT> Macro3<FONT color=red>Case Else</FONT><FONT color=red>Call</FONT> Macro4<FONT color=red>End Select</FONT><FONT color=red>End Sub</FONT></PRE>

_________________
HTH

With Regards,
Colo

This message was edited by Colo on 2002-10-24 07:40
 

Forum statistics

Threads
1,144,768
Messages
5,726,179
Members
422,660
Latest member
mrsteele

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
Top