Can I disable Worksheet_activate???

B

broogle

Any Excel guru can help me??

I have three sheets (Sheet1, Sheet2, Sheet3).

Sheet2 has Worksheet_activate(Macro) on it.
Let say, I'm working on sheet1,if I move to Sheet2, then,
Worksheet_activate in sheet2 will be activates, right?
My question is, how can I (if possible) to disable the
Worksheet_activate to run in sheet2 if I move from sheet3 to sheet2 ??
I just want the Worksheet_activate in sheet2 running, only if I move
from sheet1.
Thank you.
 
R

R.VENKATARAMAN

I am not sure whether this is correct move sanctioned by mvps
in the intermediate window of vba I type
application.enableevents=false
and hit enter
then after my work isover i again type in the intermesdiate window
application.enableevents=true
and then hit enter.
so that the worksheets activate macro of sheet2 can now work.

try this and see

=======================================
 
K

Kaak

You can use the *Private Sub Worksheet_Deactivate()* in all sheets
to set the a global var.
Then you can check in *Private Sub Worksheet_Activate()* of sheet2
where you are comming from.
And you can deside to run code if you're from sheet1.

Jeroen
 
B

Bob Phillips

This is the sort of code Jeroen was referring to. Not that I use the
worksheet codename not name, in case a user gets cute and changes the name

Public LastSheet As String

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.CodeName = "Sheet2" Then
If LastSheet = "Sheet3" Then
'ok, so let go
Else
Worksheets(ThisWorkbook.VBProject.VBComponents(LastSheet) _
.Properties("Name").Value).Activate
End If
End If
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
LastSheet = Sh.CodeName
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top