Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro-example that sets current Year and Month in your report

OK, so I'd done a simple macro that sets current Year and Month as a document is opened. I was looking for a solution here in the community and couldnt find it so I thought I might share my solution with you.

You could offcourse use this macro to set other variables...like current date for instance.

Best regards / Joakim

Sub initDate

                             '*************************************************************************************

                             'Macro name: initDate

                             'This macro sets current Year and Month - Trigger on event "When document opens"

                             'Event Trigger is set manually in Document-properties / Triggers

                             '1. Choose trigger "When document opens"

                             '2. Add activity

                             '3. Under activity, choose ”Add” + ”Extern” + ”run macro” + enter ”initDate”

                             '**************************************************************************************

                             'Set current Year - Change "datum_Year" to your corresponding Year-field

                             ActiveDocument.GetField("datum_Year").Select ActiveDocument.Evaluate("year(today())")

                             'Set current Month - Change "datum_Month" to your corresponding Month-field

                             ActiveDocument.GetField("datum_Month").Select ActiveDocument.Evaluate("num(month(today()),00)")

End Sub

0 Replies