![]() |
run a macro on a certain action
I would like to run a macro when user selects a ceratin worksheet is this
possible? |
run a macro on a certain action
In the VBE, under the "Microsoft Excel Objects" in the Project Explorer,
you'll see the list of all worksheets in your workbook. Double-click on the sheet for which you'd like the macro to apply then put your code in the Worksheet_Activate procedu Private Sub Worksheet_Activate() Your code here End Sub Subsequently, whenever this worksheet is activated, your code will run. "Jelinek" wrote: I would like to run a macro when user selects a ceratin worksheet is this possible? |
run a macro on a certain action
In the code module for the sheet:
Private Sub Worksheet_Activate() 'your code here End Sub HTH knut "Jelinek" skrev i melding ... I would like to run a macro when user selects a ceratin worksheet is this possible? |
run a macro on a certain action
Yes, that is what Event Procedures do - they are procedures that run when an
event occurs. What you want is the Workbook_SheetSelectionChange procedure. If you go into the VBA editor, make sure the Project Explorer is visible (from View menu if not). Then double click on the line that says "ThisWorkbook." All the code that is specific to the workbook goes in there and since the SheetSelectionChange is a Workbook based event you need to put the code in that module. Once you are in the module, in the code pane at the top will be two dropdown lists. From the one on the left choose Workbook, then on the right choose SheetSelectionChange. When you do this you will see the Sub declaration is created: Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) End Sub This is the sub that will run when you change the selected sheet(s); you need to put your code in there. The parameters shown mean the the sheet selected will be available to you in the variable Sh, the range that is selected is available in the variable Target, so you can use these in your code. For more info look at VBA help or search this site for the words "Excel Event Procedure." -- - K Dales "Jelinek" wrote: I would like to run a macro when user selects a ceratin worksheet is this possible? |
run a macro on a certain action
Another source of information on events
Chip Pearson's site http://www.cpearson.com/excel/events.htm -- Regards, Tom Ogilvy "Jelinek" wrote in message ... I would like to run a macro when user selects a ceratin worksheet is this possible? |
All times are GMT +1. The time now is 02:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com