Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Experts,
Can we create action which Runs macro by using if statement and condition in it?
EX. I am using below statement while creating actions If(vNo_of_rows<5000,'ExportMacro')
I want my macro to run only when value of variable vNo_of_rows less than 5000.
Problem: It is still running macro when condition is False i.e. value is greater than 5000.
Thanks,
Nishant
Possibly the execution of your expression is not happening properly. Did you put '=' sign ? or may be $ expansion is required. Try like:
= If(vNo_of_rows<5000,'ExportMacro')
Or,
= If($(vNo_of_rows)<5000,'ExportMacro')
Maybe it's easier to include the condition within the macro itself instead in the trigger. You could query your variables within the macro like:
v = ActiveDocument.Variables("vNo_of_rows").GetContent.String
if v < 5000 then
export ...
else
msgbox "to many rows, please select ..."
end if
- Marcus
Tresesco,
I tried this but issue not resolved.
Thanks,
Have you checked your variable output? Could you post your problem qvw with sample reduced data?
Marcus,
This code change will always run macro only when value is <5000. I have a sheet from which I want to run same macro even when it is greater than 5000.
Actually, If it is <5000 I want to run Export to Excel. If it is greater than 5000 then I am showing warning msg (as Qlikview text object and not VBA msgbox) with continue button. If Continue is pressed then same macro will run.
Thanks,
Tresesco,
Yes I am monitoring variable which is counting the no. of rows. But somehow it is running macro even when variable has 5000+ number. I have also prioritize Set variable action first and below it I have run Macro on condition.
Thanks,
The problem could lie here in setting the variable value and excuting the macro in a same trigger. Try to remove the set variable action from the trigger and use a definition for the variable to get it's value.
try by removing the else part from the marcus solution...
The actions which are executed by one trigger won't be executed sequentielly - therefore is the suggestion from tresesco to separate these actions by from eachother depending actions recommended.
But your further requirements (from which sheet triggered and to react on the user-message) could be included into the macro. The calling sheet could be per getactivesheetid() assigned to another variable and a msgbox had a return-value for each button which will be pressed and which could be queried in another if-loop.
- Marcus