Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
paul_ripley
Creator III
Creator III

Run a macro from Trigger

Hello

I have a simple macro that exports a chart to a file location

Sub ExportFile
 
set obj1 = ActiveDocument.GetSheetObject("CH109")
obj1.ExportBiff \\DCL1-QLIK-WV03\QlikView_UDA\III_LIVE\FIN\01_SOURCE_DATA\XLS\TotalAllocs.xls

  ActiveDocument.GetApplication.Sleep 5000

End Sub

This works but I need to run when I reload the qvw. So I went to Document Settings/Triggers/OnPostReload

But when I reload it doesn't update export the file

Am I missing something?

Many thanks

Paul

8 Replies
jerrysvensson
Partner - Specialist II
Partner - Specialist II

Hi

I guess you are running this from Publisher. That doesn't work unfortunately.

You will need to set up an external task using qv.exe /r <application.qvw> to get this to work.

paul_ripley
Creator III
Creator III
Author

Hi Jerry

The macro works on the server but for some reason I cant even get it to work on the server when manually reloading from the server. 

Miguel_Angel_Baeyens

Does the account you use in the server have rights on that share and folder? If the file already exists, is it locked?

paul_ripley
Creator III
Creator III
Author

Hi Miguel

It does have rights because when I run the macro it does update the file.  But when I try to ask the trigger to run the macro on reload it does nothing

Thanks

Paul

Miguel_Angel_Baeyens

I see, you may want to see this:

https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/UsingMacrosonQVS.htm

"The following triggers are not to be used in the QlikView Server environment, since they lack meaning or may cause unexpected results:

OnPostReduceData

OnPostReload"

paul_ripley
Creator III
Creator III
Author

OK thanks both, so it seems I wont be able to run the macro based on the trigger. Jerry mentioned using an external task to run it.  I am not sure what this.  Would either of you be able to expand a little on this.

Many thanks

Paul

Miguel_Angel_Baeyens

What Jerry means is that you can create a supporting task in the QMC > System > Supporting Tasks > External Program which can run anything that can be executed in Windows (.bat, .exe or .msi files for example). In your case, it could be a .BAT file that includes something like

qv.exe /r Document.qvw

This will run QlikView Desktop and will reload the script of the file Document.qvw. Once finished, it will trigger the OnPostReload actions.

As any other task, it will appear in the QMC and can be triggered when another task has succeded, or failed, or on an external event (i.e.: using EDX).

See https://help.qlik.com/en-US/qlikview/November2018/Subsystems/QMC/Content/QV_QMC/QMC_System_Supportin...

Command line parameters available: https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Starting_Qli...

paul_ripley
Creator III
Creator III
Author

Many thanks, will look into it