Internal Macro Interpreter

QlikView objects are accessible via automation from inside QlikView by means of the built-in scripting engine.

Invoking Macros

Macros written in VBScript or JScript, inside a QlikView document can be invoked in a number of different ways:

Document Events:

  • A macro can be run after opening a QlikView document.
  • A macro can be run after script re-execution.
  • A macro can be run after the Reduce Data command.
  • A macro can be run after a selection in any field in a document.
  • A macro can be run when the value of any variable changes in a document.

Macros that are invoked from document events are created from the Document Properties: Triggers page.

Sheet Events:

  • A macro can be run after a sheet is activated.
  • A macro can be run when a sheet is deactivated.

Macros that are invoked from sheet events are created from the Sheet Properties: Triggers page.

Sheet Object Events:

  • A macro can be run after a sheet object is activated.
  • A macro can be run when a sheet object is deactivated.

Macros that are invoked from sheet object events are created from the Sheet Properties: Triggers page.

Button Events:

  • A button can be defined as a macro button.

A macro that is invoked from a macro button event is created from the button's Actions page.

Field Events:

  • A macro can be run when a selection has been made in a specified field.
  • A macro can be run when a selection is made in any field which is logically associated to a specified field.
  • A macro can be run when selections are locked in a specific field.
  • A macro can be run when selections are unlocked in a specific field.

Macros that are invoked from field events are created from the Document Properties: Triggers page.

Variable Events:

  • A macro can be run when new values are directly entered into specified script variables.
  • A macro can be run when the value of the specified variable changes as a result of changes in other variables or the logical state of the document.

Macros that are invoked from variable events are created from the Document Properties: Triggers page.

Macro Editor:

Irrespective of how they are triggered, macros are created and edited in the Edit Module dialog.

Examples:  

This section gives you an example of a VBScript macro, which can be very useful.

Using VBScript Input Boxes for User Interaction

rem ** Clear selections, ask for product, **

rem ** select that product, **

rem ** go to sheet "Market", **

rem ** show pivot table "Sales" **

Sub ChooseValue

Set q = ActiveDocument

q.ClearAll (false)

Set f = q.Fields("Model Name")

x = inputbox ("Enter product")

f.Select(x)

set s = q.Sheets("Market")

s.Activate

s.SheetObjects("Sales").Activate

end sub

Special Library Functions for JScript

Whereas the standard VBScript functions InputBox and MsgBox can be used freely in VBScript macros, no direct counterpart is available when using JScript. For this purpose a special library qvlib has been added for these actions. The functions are demonstrated in the example below.

// JScript

function Test()

{

personName = qvlib.InputBox("What is you name?")

msg = "Hello " + personName + " !"

qvlib.MsgBox(msg)

}

The qvlib functions actually work also in VBScript macros as shown in the example below, but in this case you might as well use the generic VBScript functions InputBox and MsgBox.

rem VBScript

sub TestModule

name = qvlib.InputBox("What is your name?")

msg = "Hello "

msg = msg + name + " !"

qvlib.MsgBox(msg)

end sub

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?