This post demonstrates how to use the Qlikview Button object to run a VBScript Macro. In some instances, you would like to setup buttons within your Qlikview application, allowing users to initiate actions to interact with the app. Qlikview Button objects provide a robust set of actions you can setup to accomplish various tasks. The focus of this post is simply showing you how to setup a very basic VBScript macro to run on the click of a button. More detailed examples (different posts on the site) are listed at the end of this post.
Qlikview Quick Tips: Qlikview Button Run Macro
First, add a Button to your Qlikview application:
In the Button properties, make the following updates:
In the “General” tab, add Button Text “Run Macro”
In the “Actions” tab, click on “Add”, then select External for the Action Type, then Run Macro for the Action. Click OK.
Next, click on the “Edit Module…” button within the “Actions” tab, and add the Sub Routine below:
1 2 3 4 5 6 7 |
Sub RunMacro MsgBox "Run a Macro with Button!",0, "Macro Success" End Sub |
Also, make sure you set the following under “Requested Module Security” in the lower left margin of the Edit Module Window:
- Requested Module Security = System Access
- Current Local Security = Allow System Access
These settings are defined by Qlikview Help:
Requested Module Security:
- By selecting Safe Mode the document designer indicates that the macros in this QlikView document contain no code that can access either the system or applications outside QlikView. If such code is encountered during macro execution in a document declared to be in Safe Mode, the execution will fail.
- By selecting System Access mode the document designer ensures that the end user will be prompted when opening the document to either approve system access (Allow System Access), disable all macros in the document (Disable Macros) or allow only macros without system access (Safe Mode).
Current Local Security:
- When opening a document declared to be in safe mode but containing potentially “unsafe” macro code, the user will be prompted (see Requested Module Security above). The user’s action will be remembered by the system but this setting can be changed at a later time from this menu. Macro security level can be set to Don’t Run at All, Only Safe Mode or Allow System Access.
Once you Qlik “OK” above, all you need to do now is assign the Macro Name in the “Actions” tab.
Click OK. You now have a button that will execute the module “RunMacro”. Go ahead and click on the button. You will see the following:
There you have it! You just ran a VBScript macro by the click of a button!
For more detailed examples of VBScript macros, please check out the following posts:
- Qlikview Macro Field Event Trigger
- Qlikview Macro Loop through items in List Box
- Qlikview Export to Excel – Part 1
- Qlikview Export to Excel – Part 2
- Qlikview Format Multiple List Boxes
- Qlikview Open URL
- Qlikview Macro to Capture Table Box Fields
- Qlikview Export Chart to QVD
- Qlikview Select in Field
Additional Content
Check out more examples by visiting my Home Page
Here you will find topics covering Qlikview SQL Server Excel VBA