Why wouldn't calling the Activate sub for a sheet automatically call that sheet's Worksheet_Activate

  • Thread starter Thread starter Scott Lyon
  • Start date Start date
S

Scott Lyon

I'm encountering the strangest thing, and I'm trying to figure out why it's
doing what it's doing.


Basically, my application is a VBA app, written in Excel 2002. In the
"ThisWorkbook.Workbook_Open" sub, there is a line that activates the first
tab. The line of code looks like this:

shtStart.Activate

Where shtStart is the name of the worksheet in question.


Within that worksheet's VBA code, there is the WorkSheet_Activate() sub, and
code within it.


But it seems that when the shtStart.Activate in the Workbook_Open sub is
called, it's not then (automatically) calling the WorkSheet_Activate() in
shtStart. I've even put break-points in the WorkSheet_Activate() sub, and
then ran the Workbook_Open sub (one line at a time), and still not hitting
the WorkSheet_Activate() sub.


What am I missing? Any ideas/suggestions?


Thanks!
-Scott
 
Is shtStart already the activesheet because it was the activesheet when you
last saved the workbook. Unless another sheet is active and you activate
shtStart, the activate event does not fire.
 
because the event will be triggered only when there are a
change on the active sheet(If the active sheet is shtStart
there will not execute the event), you need to use a code
like this:


If ActiveSheet.Name = "shtStart" Then
Call Workbook_SheetActivate(shtStart)
Else
shtStart.Activate
End If
 
Ahhh, that worked. Thanks guys!

-Scott

pancho said:
because the event will be triggered only when there are a
change on the active sheet(If the active sheet is shtStart
there will not execute the event), you need to use a code
like this:


If ActiveSheet.Name = "shtStart" Then
Call Workbook_SheetActivate(shtStart)
Else
shtStart.Activate
End If
 
Back
Top