Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call to run macro when shett activated? 2

Status
Not open for further replies.

brengine

Mechanical
Apr 19, 2001
616
Lets say I have a Workbook with 2 Sheets in it, Sheet 1 and Sheet 2. Is there a way I can make a macro (automatically) run every time the user selects/activates Sheet 2? Also, if the file is opened and Sheet 2 is the active Sheet, I would like the macro to (automatically) run then too.

Thanks,
Ken
 
Replies continue below

Recommended for you

The Worksheet_Activate() event handler will do what you want. Put in there whatever code you want to be run. (This event handler can be found in the code window of the appropriate sheet object.)

HTH
 
Denial,

Can you give more detail for the VB-illiterates like me? Where does Worksheet_Activate() go? Is it part of the macro, or does it call the macro? Thanks.
 
1. Go to Tools|Macro|Visual Basic Editor (or hit ALT-F11).
2. Open the Projects exploere (CTL-R)
3. Select the sheet whose events you're looking for
4. In the DropDown at the top left of the sheet code window Select Worksheet
5. In the DropDown top right select Activate
6. Put your code here:
[tt]Private Sub Worksheet_Activate()
'' Your code
End Sub[/tt]

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting
 
WOW! That was so easy. I can't believe I spent so many hours on this.
Thanks!
Ken
 
Can this be applied to everytime you check out and check in something from and to the vault?
 
Not sure what you mean by the vault. Worksheet_Activate is fired each time the worksheet gets focus from within the app.

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
Sorry, we call our PDMWorks server the vault. What I meant was, is there an event that gets triggered upon checking in or out from PDMWorks? That way a macro would be automatically run whenever a part gets checked in or out.
 
Sorry again! I found this port on a search and didnt realize it was specific to spreadsheets. But if anyone works with SolidWorks and has an answer, please let me know.
 
You'll do better to ask this in forum559

Good Luck
johnwm
________________________________________________________
To get the best from these forums read faq731-376 before posting

UK steam enthusiasts:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor