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: 
Anonymous
Not applicable

Use of selected value in macro

I have a macro to export some data from QlikView to Excel. In QlikView I have a multibox with a table column called "Cycle" which can take the following values:"Cycle 1","Cycle 2","Cycle 3" or none of these values. How can I change what my macro does, depending on whether I have selected a Cycle value or not, and the value of the said Cycle value?

19 Replies
tamilarasu
Champion
Champion

Here you go. Note that your Getvariable syntax is also not correct.

SET cycle_flag = Activedocument.Fields("Name Of Your Field").GetSelectedValues

if cycle_flag(i).text = "Cycle1" then

Start_value = ActiveDocument.GetVariable("Cycle1_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle1_stop").GetContent.String

else

if cycle_flag(i).text = "Cycle2" then

Start_value = ActiveDocument.GetVariable("Cycle2_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle2_stop").GetContent.String

else

if cycle_flag(i).text = "Cycle3" then

Start_value = ActiveDocument.GetVariable("Cycle3_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle3_stop").GetContent.String

end if

end if

end if

Anonymous
Not applicable
Author

Now I'm getting an "Invalid procedure call or argument" error...

Here's the whole code:

set cycle_value = ActiveDocument.Fields("Cycle").GetSelectedValues

if cycle_value(i).text = "Cycle1" then

Start_value = ActiveDocument.GetVariable("Cycle1_start")

End_value = ActiveDocument.GetVariable("Cycle1_stop")

else

if cycle_value(i).text = "Cycle2" then

Start_value = ActiveDocument.GetVariable("Cycle2_start")

End_value = ActiveDocument.GetVariable("Cycle2_stop")

else

if cycle_value(i).text = "Cycle3" then

Start_value = ActiveDocument.GetVariable("Cycle3_start")

End_value = ActiveDocument.GetVariable("Cycle3_stop")

end if

end if

end if

tamilarasu
Champion
Champion

Mihai,

I have already updated the above code.

set cycle_value = ActiveDocument.Fields("Cycle").GetSelectedValues

if cycle_value(i).text = "Cycle1" then

Start_value = ActiveDocument.GetVariable("Cycle1_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle1_stop").GetContent.String

else

if cycle_value(i).text = "Cycle2" then

Start_value = ActiveDocument.GetVariable("Cycle2_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle2_stop").GetContent.String

else

if cycle_value(i).text = "Cycle3" then

Start_value = ActiveDocument.GetVariable("Cycle3_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle3_stop").GetContent.String

end if

end if

end if

Anonymous
Not applicable
Author

There seems to be an error at the : if cycle_value(i).text = "Cycle1" then

error.PNG

tamilarasu
Champion
Champion

I think you have not selected any values in the Cycle field or you must be selecting multiple values.

Anonymous
Not applicable
Author

I have multiple values selected in a multi-box, but only one selected in the Cycle field. Could that be the issue?

tamilarasu
Champion
Champion

Can you try this script and let me know whether you are getting any error message or not.


If ActiveDocument.Fields("Cycle").GetSelectedValues.Count = 0 Then

Msgbox "Nothing is selected"

Else

if ActiveDocument.Fields("Cycle").GetSelectedValues.Count >1 Then

Msgbox "Multiple Values Selected"

Else


set cycle_value = ActiveDocument.Fields("Cycle").GetSelectedValues

if cycle_value(i).text = "Cycle1" then

Start_value = ActiveDocument.GetVariable("Cycle1_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle1_stop").GetContent.String

else

if cycle_value(i).text = "Cycle2" then

Start_value = ActiveDocument.GetVariable("Cycle2_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle2_stop").GetContent.String

else

if cycle_value(i).text = "Cycle3" then

Start_value = ActiveDocument.GetVariable("Cycle3_start").GetContent.String

End_value = ActiveDocument.GetVariable("Cycle3_stop").GetContent.String

end if

end if

end if

End If

End If

Anonymous
Not applicable
Author

I've run your script but I didn't got any message. At all.

Anonymous
Not applicable
Author

I've managed to solve the error by simply replacing cycle_value(i).text with cycle_value(0).text. I will mark your first answer as the correct. Thank you for all the help!

tamilarasu
Champion
Champion

My bad. Glad that you found the mistake. Have a nice day!