Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Frank_Hartmann
Master II
Master II

store looped values in a variable (macro)

Hi Guys

I have the following macrocode which returns activated objectIDs.

Sub getActiveObjectID

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

for i=lbound(objs) to ubound(objs)

if objs(i).IsActive then

var =  right(objs(i).GetObjectId,4)

msgbox(var)

end if

next

End Sub

For example If I have CH01, CH02 and TX01 activated how can i store this as a string in a variable while executing the macro, like:

msgBox(Variable) = "CH01","CH02","TX01"

Any Ideas?

1 Solution

Accepted Solutions
el_aprendiz111
Specialist
Specialist

Hi,

Sub getActiveObjectID

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

for i=lbound(objs) to ubound(objs)

if objs(i).IsActive then

var =   var &  chr(34)& right(objs(i).GetObjectId,4) &  chr(34) & chr(44)

msgbox(var)

end if

next

set v = ActiveDocument.Variables("MyVar")

     v.SetContent var,true

End Sub

View solution in original post

4 Replies
el_aprendiz111
Specialist
Specialist

Hi,

Sub getActiveObjectID

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

for i=lbound(objs) to ubound(objs)

if objs(i).IsActive then

var =  right(objs(i).GetObjectId,4)

msgbox(var)

end if

next

set v = ActiveDocument.Variables("MyVar")

     v.SetContent var,true

End Sub

Frank_Hartmann
Master II
Master II
Author

hi fer fer,

thank you for your answer

your piece of code only adds the last marked object to the variable.

In the below example i expect the output for MyVar to be :

MyVar = TX05,TX06,TX07


Aufnahme_2017_07_11_21_23_02_241.gif

el_aprendiz111
Specialist
Specialist

Hi,

Sub getActiveObjectID

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

for i=lbound(objs) to ubound(objs)

if objs(i).IsActive then

var =   var &  chr(34)& right(objs(i).GetObjectId,4) &  chr(34) & chr(44)

msgbox(var)

end if

next

set v = ActiveDocument.Variables("MyVar")

     v.SetContent var,true

End Sub

Frank_Hartmann
Master II
Master II
Author

that works.

thank you very much!