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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,136
Members
448,551
Latest member
Sienna de Souza

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