Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Execute a Macro inside load script

Hi All,

is possible execute an Qlikview macro inside a load script?

Tks

1 Solution

Accepted Solutions
Not applicable
Author

Sure! Just create it and then use it in the macro - Qlikview will look for it at load time if it cannot find a native function. For example I created this function which I use in a script:

Function MonthDiff (startdate, enddate)
' return number of months between two dates
If IsDate(startdate) and IsDate(enddate) Then
MonthDiff = DateDiff("m", startdate, enddate)
End If
End Function

Regards,

Gordon

View solution in original post

16 Replies
Not applicable
Author

Sure! Just create it and then use it in the macro - Qlikview will look for it at load time if it cannot find a native function. For example I created this function which I use in a script:

Function MonthDiff (startdate, enddate)
' return number of months between two dates
If IsDate(startdate) and IsDate(enddate) Then
MonthDiff = DateDiff("m", startdate, enddate)
End If
End Function

Regards,

Gordon

Not applicable
Author

Tks Gordon for your reply.

I created a function and into load script I execute it by CALL command.

Call MonthDiff()

Regards.

Not applicable
Author

Hi, I tried this very same code and get "Script line error" in Call MonthDiff()

what could it be, has the syntax changed?

thanks,

Miguel_Angel_Baeyens

Hello,

If you are calling the function from the load string, do as follows instead

LET vExecFunction = MonthDiff();


If the function in the macro editor (CTRL + M) is built using Sub / End Sub instead of Function / End Function, then use CALL in the script.

Hope that helps.

Not applicable
Author

If you use the code as in my example then it is a function not a sub - you call a sub but not a function. So, to use my code you would simply have in the script:

MonthDiff(date1, date2)

Regards,

Gordon

marcel_olmo
Partner Ambassador
Partner Ambassador

Hey Gordon, I'm just trying the same as you. Loading a macro inside the loading script.

I have many problems doing that.

When I write in my loading script :

call myFunction()

I got an error message.

My suggestions is :

1- You can only call the macros in VBScript ( I have my macros in jscript).

2-I've tried both ways to get the same result (functions in javascript and vbscript), and I still can't get it work.

Any Ideas about what I'm doing wrong??

Many thanks in advance!!

Not applicable
Author

I dont undertstand what the problem is - I use the function (VBS) in several documents and they work just fine in v9sr4 and previously in v8.2.

Is your problem just the dates you are passing to the function being invalid or the wrong format?

Regards

Gordon

marcel_olmo
Partner Ambassador
Partner Ambassador

Well, in fact I'm not using your dates function. Actually, I have a document with "jscript" macros. And I would like to execute a macro (that generates xml files) before reloading the document with the new day information.

I know that a useful solution would be separate the execution in two files. First execute the document that contains the macro, and then reload the document with the information generated in the previous document.

But I still want to do it in the same doucment, I think it would be cooler ;).

Hope you can give me some advices about that.

Many thanks in advance!!

Not applicable
Author

How about using the document OnOpen event to execute the macro? You would need to be able to identify from within the macro when the action should be fired as it will fire every time (including user access) which you can do by passing a variable and value through the command line interface using the /v switch.

Regards,

Gordon