Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Customer & Partners, DEC. 9, 11 AM ET: Qlik Product & Strategy Roadmap Session: Data Analytics REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
ilanbaruch
Specialist
Specialist

Execute Macro from Load Script

hi all

in my model I have a Macro script

I want to execute this macro from within the load script, is that possible ?

advanced thanks

Labels (2)
2 Solutions

Accepted Solutions
cwolf
Creator III
Creator III

For example you have a function:

function Test1()
	' Type your VB script here
        .
        .
        .
 	'return a result
 	Test1="Ok"
end function

 

then the line

let result1=Test1();

will execute the function.

 

You can also use functions with parameters:

function Test2(param1,param2)
 	Test2=param1 & " " & param2 & "!"
end function

 

let result2=Test2('Hello','World');

The variable result2 now contains "Hello World!".

View solution in original post

rwunderlich

As @cwolf said, you can trigger Functions from the script, but not Subs. If your code is in a Sub, you will need to define a Function that calls the Sub. 

When called from the script,  VB Macro code cannot access the ActiveDocument object. So if you trying to do something like access chart data your macro will not work from script. 

-Rob

View solution in original post

9 Replies
cwolf
Creator III
Creator III

Macro functions can be used like QlikView functions in the load script. For example via a variable assignment:

let result=VBFunctionName();

ilanbaruch
Specialist
Specialist
Author

and than ? 

execute ?

cwolf
Creator III
Creator III

For example you have a function:

function Test1()
	' Type your VB script here
        .
        .
        .
 	'return a result
 	Test1="Ok"
end function

 

then the line

let result1=Test1();

will execute the function.

 

You can also use functions with parameters:

function Test2(param1,param2)
 	Test2=param1 & " " & param2 & "!"
end function

 

let result2=Test2('Hello','World');

The variable result2 now contains "Hello World!".

View solution in original post

ilanbaruch
Specialist
Specialist
Author

first of all thank you.

I have the macro script as in your example. it is ready and working if I trigger it from UI.

the macro script is in the macro script section (Ctrl+M) I want to trigger it from the script editor  (Ctrl+E) .

i set the variable as you suggested but it isn't working

cwolf
Creator III
Creator III

See attachement.

rwunderlich

As @cwolf said, you can trigger Functions from the script, but not Subs. If your code is in a Sub, you will need to define a Function that calls the Sub. 

When called from the script,  VB Macro code cannot access the ActiveDocument object. So if you trying to do something like access chart data your macro will not work from script. 

-Rob

View solution in original post

ilanbaruch
Specialist
Specialist
Author

Hi, thank you for you replay.

you are right , the function is within a sub.

how can call this sub from a function ?

rwunderlich

Sub MySub
  ....
End Sub

Function MyFunction
  Call MySub
End Function
ilanbaruch
Specialist
Specialist
Author

Thank you