Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am looking for a feature that would allow me to store a few standard macros I have written in a text file, and then reference that text file in multiple QVWs to include those macros.
In other words, is it possible to do an $(include=filename.txt) or similar, but for macros and not script?
that way I can just modify the text file and it will be captured throughout all my QVWs, instead of fixing it manually in the module of every single one.
Thanks for the info in advance.
You can actually do this by actually making the executed macro code dynamic, using the VBS ExecuteGlobal command.
See the attached (save them to the same location). The document has a variable vVar1 which has my name in it (fame at last?!). In the module code is a macro called runCode that can be executed by clicking on the 'test' button on the main sheet. This calls a sub called include that receives the passed file name, reads the contents and then executes the contents using ExecuteGlobal.
So the code isnt 'included' but dynamically executed - try changing the msgbox in 'hello.txt' in between clicking 'test' and see the results change.
This also means that the document doesnt have to be refreshed or anything to use the changed macro code. So you would just put your common macro code into individual .txt files and where you want to use them execute the sub as occurs in 'runCode' in the module with the corresponding file name.
Hope this helps.
Regards,
Gordon
Hi Gordon,
Thanks for the reply, and that does seem to work. Unfortunately, I was hoping to use a native QlikView command or built-in feature so I didn't have to give the document "System Access." This wouldn't run on our server, and probably wouldn't work in AJAX.
All my macros are safe QlikView API calls (zoom, export, print, setting variables, etc) that are functional on the server through the AJAX client, was just wondering if there was an easy way to store those centrally in one place, and then easily include/reference them in each QVW.
Your workaround definitely works and is simple enough to implement, but I suppose there is no other method?
Here's a variation on Gordon's solution that doesn't require system access.
1. Load the macro text in your document's script.
Macro:
LOAD @1:n as MacroText, RecNo() as MacroLine
FROM macros.txt (fix, codepage is 1252);
2. In your macro module, insert the line:
ExecuteGlobal ActiveDocument.Evaluate("concat(MacroText, chr(10), MacroLine)")
The ExecuteGlobal will run everytime the doc is loaded into RAM, so it should work just fine on the server with any client.
-Rob