Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default On going onto a sheet run a macro?

Is it possible to run a macro when a sheet it clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default On going onto a sheet run a macro?

Stu,

You can use the Activate event procedure. For example, put the following
code in the ThisWorkbook code module:


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox "You activated: " & Sh.Name
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"Stu" wrote in message
...
Is it possible to run a macro when a sheet it clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default On going onto a sheet run a macro?

Hi Stu

In its simplest form; rightclick the Sheet tab, choose View Code, paste this in:

Private Sub Worksheet_Activate()
Call MyMacro
End Sub

Sub MyMacro()
MsgBox "Yo"
End Sub

It runs when you click the sheet's tab. If you need this code to run when activating one
of several windows then you also need to program the Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and troublesome at the same time.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message ...
Is it possible to run a macro when a sheet it clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default On going onto a sheet run a macro?

Can you run the macro from a module or do you have to run it from that
sheets code?

Thanks
--
Stu
"Harald Staff" wrote in message
...
Hi Stu

In its simplest form; rightclick the Sheet tab, choose View Code, paste

this in:

Private Sub Worksheet_Activate()
Call MyMacro
End Sub

Sub MyMacro()
MsgBox "Yo"
End Sub

It runs when you click the sheet's tab. If you need this code to run when

activating one
of several windows then you also need to program the

Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and troublesome at the

same time.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message

...
Is it possible to run a macro when a sheet it clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default On going onto a sheet run a macro?

You can (perhaps even should) put MyMacro on a standard module and call it from anything
anywhere. But the activate event must stay where it is. But events code (like Activate)
lives in their spesific modules, here the sheet module.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message ...
Can you run the macro from a module or do you have to run it from that
sheets code?

Thanks
--
Stu
"Harald Staff" wrote in message
...
Hi Stu

In its simplest form; rightclick the Sheet tab, choose View Code, paste

this in:

Private Sub Worksheet_Activate()
Call MyMacro
End Sub

Sub MyMacro()
MsgBox "Yo"
End Sub

It runs when you click the sheet's tab. If you need this code to run when

activating one
of several windows then you also need to program the

Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and troublesome at the

same time.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message

...
Is it possible to run a macro when a sheet it clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default On going onto a sheet run a macro?

Hello,

I have been trying to add this type of code to a sheet
when the sheet is built using VBA modules. I do not see
how to plug the "Private Sub Worksheet_Activate()" code
onto the new sheet module. I need to have this completly
invisible to the user.

How can we reference the new sheet module programatically?


Any ideas appreciated.

thank you,
Scott

-----Original Message-----
You can (perhaps even should) put MyMacro on a standard

module and call it from anything
anywhere. But the activate event must stay where it is.

But events code (like Activate)
lives in their spesific modules, here the sheet module.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message

...
Can you run the macro from a module or do you have to

run it from that
sheets code?

Thanks
--
Stu
"Harald Staff" wrote in message
...
Hi Stu

In its simplest form; rightclick the Sheet tab,

choose View Code, paste
this in:

Private Sub Worksheet_Activate()
Call MyMacro
End Sub

Sub MyMacro()
MsgBox "Yo"
End Sub

It runs when you click the sheet's tab. If you need

this code to run when
activating one
of several windows then you also need to program the

Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and

troublesome at the
same time.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message

...
Is it possible to run a macro when a sheet it

clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu








.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On going onto a sheet run a macro?

See Chip Pearson's site for this

http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy

Scott wrote in message
...
Hello,

I have been trying to add this type of code to a sheet
when the sheet is built using VBA modules. I do not see
how to plug the "Private Sub Worksheet_Activate()" code
onto the new sheet module. I need to have this completly
invisible to the user.

How can we reference the new sheet module programatically?


Any ideas appreciated.

thank you,
Scott

-----Original Message-----
You can (perhaps even should) put MyMacro on a standard

module and call it from anything
anywhere. But the activate event must stay where it is.

But events code (like Activate)
lives in their spesific modules, here the sheet module.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message

...
Can you run the macro from a module or do you have to

run it from that
sheets code?

Thanks
--
Stu
"Harald Staff" wrote in message
...
Hi Stu

In its simplest form; rightclick the Sheet tab,

choose View Code, paste
this in:

Private Sub Worksheet_Activate()
Call MyMacro
End Sub

Sub MyMacro()
MsgBox "Yo"
End Sub

It runs when you click the sheet's tab. If you need

this code to run when
activating one
of several windows then you also need to program the
Workbook_WindowActivate event in
ThisWorkbook module. Post back if that's relevant and

troublesome at the
same time.

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Stu" wrote in message
...
Is it possible to run a macro when a sheet it

clicked on to be viewed?
If so how do I do it?

Thanks
--
Stu








.



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
Macro to lookup a sheet, number, then display in origonal sheet abbsy3 New Users to Excel 3 November 9th 10 12:19 PM
How to move rows from one sheet to another sheet (macro) Stacey Excel Discussion (Misc queries) 1 December 30th 09 02:52 PM
macro to: Add new sheet, then rename new sheet with todays date Paul Excel Worksheet Functions 3 September 29th 07 03:17 AM
HELP!! Unhide Sheet with Macro and focus on other sheet [email protected] Excel Discussion (Misc queries) 2 May 23rd 06 07:17 PM
2 questions, copying data from sheet to sheet and assigning macro Boris Excel Worksheet Functions 0 December 16th 04 06:11 PM


All times are GMT +1. The time now is 12:07 AM.

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

About Us

"It's about Microsoft Excel"