ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Before Worksheet Close (https://www.excelbanter.com/excel-programming/433634-before-worksheet-close.html)

jswalsh33

Before Worksheet Close
 
Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another worksheet?

Thanks for your help.

Jim Walsh

Bob Phillips[_3_]

Before Worksheet Close
 
Private Sub Worksheet_Deactivate()
....your code
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"jswalsh33" wrote in message
...
Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another
worksheet?

Thanks for your help.

Jim Walsh




Jacob Skaria

Before Worksheet Close
 
DeActivate event is triggered when you select another worksheet..

Private Sub Worksheet_Deactivate()
MsgBox "ok"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"jswalsh33" wrote:

Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another worksheet?

Thanks for your help.

Jim Walsh


Dave Peterson

Before Worksheet Close
 
If the two worksheets are in separate workbooks, you may want to use the
workbook event:
Private Sub Workbook_Deactivate()

(maybe both????)

jswalsh33 wrote:

Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another worksheet?

Thanks for your help.

Jim Walsh


--

Dave Peterson

jswalsh33

Before Worksheet Close
 
Bob,

That works good, but it allows the newly selected worksheet to be activated
before the the Deactivate code operates. I tried putting in
"Application.ScreenUpdating = False" as the first line of code but that did
not prevent it. Is there a way to keep the screen from switching to the newly
selected worksheets?

Thanks Again,

Jim Walsh

"Bob Phillips" wrote:

Private Sub Worksheet_Deactivate()
....your code
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"jswalsh33" wrote in message
...
Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another
worksheet?

Thanks for your help.

Jim Walsh





Bob Phillips[_3_]

Before Worksheet Close
 
I can't see it because that sheet is not deactivated until something else is
activated.

--
__________________________________
HTH

Bob

"jswalsh33" wrote in message
...
Bob,

That works good, but it allows the newly selected worksheet to be
activated
before the the Deactivate code operates. I tried putting in
"Application.ScreenUpdating = False" as the first line of code but that
did
not prevent it. Is there a way to keep the screen from switching to the
newly
selected worksheets?

Thanks Again,

Jim Walsh

"Bob Phillips" wrote:

Private Sub Worksheet_Deactivate()
....your code
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"jswalsh33" wrote in message
...
Is there a way to run a particular macro when focus is change from a
particular worksheet to any other worksheet by selecting another
worksheet?

Thanks for your help.

Jim Walsh








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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com