1. Put your common code in a file, say "commonFunctions.vbs".
2. Add this macro code to your Qlikview Document module:
Call IncludeCommon Sub IncludeCommon Dim objFSO, file, str Set objFSO = CreateObject("Scripting.FileSystemObject") Set file = objFSO.OpenTextFile("commonFunctions.vbs") str = file.ReadAll file.Close ExecuteGlobal str End Sub
Press the "Check" button. Bingo, your externally defined Functions and Subs are available. Your document must be granted system access for this to work.
Changes made to the external file will be picked up each time the document is opened. If you are developing and don't want to open/close the doc, making an edit change to the document module will pick up the changes as well.
Let me know if this works for you. I haven't actually tried this in production.
One method could be to create a Master .qvw containing the macros and password protect it, then use code in the destination document to read the master code and overwrite it. I have managed to do this as follows (all documents in same folder to simplify) ...
1) Create ModuleMaster.qvw and password protect. Module needs to include the import .vbs routine as above.
2) Create .vbs file with following code ...
Function GetScript(Doc) set QV=CreateObject("QlikTech.QlikView") set Doc = QV.OpenDoc (Doc) set props = Doc.GetProperties GetScript = props.VBModule Doc.CloseDoc End Function
Sub ModifyScript set docprop = ActiveDocument.GetProperties docprop.VBModule = GetScript("ModuleMaster.qvw") ActiveDocument.SetProperties docprop End Sub
3) In destination document, include just the import .vbs routine again, click check and the ModifyScript sub should be available.
4) Run the ModifyScript (enter ModuleMaster.qvw credentials if needed) and the script should be overwritten. As we have included the import .vbs routine in ModuleMaster, it is retained for future use.
A word of warning though, I did observe that on one test my module wouldn't display the subs after "Check"-ing and I had to close and restart QV, but hopefully this could give some ideas.