Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Macro to run when a particular sheet is opened

I'm trying to work out how to get a macro to run every time I open a
particular sheet of a workbook without having to create a button or 'run' the
macro.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro to run when a particular sheet is opened

Here is an example. Install the following event macro in the worksheet code
area:

Private Sub Worksheet_Activate()
MsgBox ("Hello Derek")
End Sub

It will run whenever the tab is activated. If your macro is in a standard
module, you can call it from the event macro.


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm


--
Gary''s Student - gsnu200859


"Derek N" wrote:

I'm trying to work out how to get a macro to run every time I open a
particular sheet of a workbook without having to create a button or 'run' the
macro.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Macro to run when a particular sheet is opened

Right click the tab you want and select view code. The VBE will open up. Just
above the code window are 2 drop downs. Change the one on the left from
General to Worksheet. When you do this a code stub for selection change will
be written. Now from the drop down on the right select the Activate event. A
code stub for activate will be added. You can now delete the code stub for
Selection Change.

Any code added to the activate code stub will run when the sheet is selected.
--
HTH...

Jim Thomlinson


"Derek N" wrote:

I'm trying to work out how to get a macro to run every time I open a
particular sheet of a workbook without having to create a button or 'run' the
macro.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Macro to run when a particular sheet is opened

Right-click on the sheet tab and "View Code"

Copy/paste this code to the sheet module.

Private Sub Worksheet_Activate()
macroname
End Sub


Gord Dibben MS Excel MVP

On Fri, 24 Jul 2009 07:27:01 -0700, Derek N <Derek
wrote:

I'm trying to work out how to get a macro to run every time I open a
particular sheet of a workbook without having to create a button or 'run' the
macro.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Macro to run when a particular sheet is opened

Thanks everyone. After a couple of endless l(oops), it's working perfectly.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check a sheet each time file opened? Don Excel Discussion (Misc queries) 1 February 24th 09 06:27 PM
Can I set up Excel sheet that auto increments a no. when opened Craneman Excel Discussion (Misc queries) 2 May 1st 08 09:53 AM
To fix a sheet in MS Office to be opened first always Shariq Excel Worksheet Functions 3 January 17th 06 11:59 AM
How to run a macro as soon a a workbook (.xls) is opened? Sangamesh Acharya Excel Worksheet Functions 1 December 15th 05 11:15 PM
Links to other sheets only work if the sheet is opened Arnold de Lange Excel Discussion (Misc queries) 3 December 28th 04 03:12 PM


All times are GMT +1. The time now is 12:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"