Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save an extra $150 Dec 1–7 with code CYBERWEEK - stackable with early bird savings: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro on OnActivateSheet is not running!!!

I create a Macro on OnActivateSheet to select default period. When I click this sheet tab, the Macro runs. But when I go into this sheet through button(another Macro), it can not runs.

Why?

sub SetDefTime
vDefYear=GetVarValue("vDefYear")
vDefMonthFmt=GetVarValue("vDefMonthFmt")
set vYear = ActiveDocument.Fields("Year")
set vMonthFmt = ActiveDocument.Fields("MonthFmt")
ActiveDocument.ClearAll
vYear.Select vDefYear
vMonthFmt.Select vDefMonthFmt
end sub

3 Replies
Miguel_Angel_Baeyens

Hello John,

Are you using version 9? If so, you can add an action to your button, design -> activate sheet. Is the same exact code which is running from both macro and when clicking on tab?

Anonymous
Not applicable
Author

Dear Miguel,

My button is also an activate sheet function, why it can't activate the sheet?

sub

v_sheet_name = .........
for i = 0 to ActiveDocument.NoOfSheets - 1
set ss= ActiveDocument.GetSheet(i)
if v_sheet_name=ss.GetProperties.Name then
Activedocument.Sheets(v_sheet_name).Activate
exit for
end if
next

end sub

Miguel_Angel_Baeyens

Hello John,

You are probably using the Object ID ("SH01") instead of the name ("Main") so the property .Name is never matched. Apart from that, your code seem ok. Anyway, I'd suggest you to add that action instead of macros (I prevent from using macros whenever I can) to the button, If you just want to activate that tab.