Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Learn how to migrate to Qlik Cloud Analytics™: On-Demand Briefing!
cancel
Showing results for 
Search instead for 
Did you mean: 
beanmachine
Partner - Contributor III
Partner - Contributor III

How to get the id of a currently selected object in a macro

I have a macro which writes out an export file and then prepends a heading to that file to match a proprietary import format. I want to use the same macro for a range of different objects (straight tables) using a button. Currently I am hard coding the ID for test purposes.

The user will select the object they want and then hit export. The problem is, how do I tell my macro the id of the object the user has selected? I can't seem to find a API function for this.

Appreciate any information on the subject.

Thanks

BeanMachine

1 Solution

Accepted Solutions
Not applicable

You may want to try using the IsActive property -- not sure if there is a property/method that returns activesheetobjects. Example below:

rem ** minimize all active sheet objects on active sheet **
set s=ActiveDocument.ActiveSheet
objs=s.GetSheetObjects
for i=lbound(objs) to ubound(objs)
if objs(i).IsActive then objs(i).Minimize
next

I hope this helps.

View solution in original post

3 Replies
Not applicable

You may want to try using the IsActive property -- not sure if there is a property/method that returns activesheetobjects. Example below:

rem ** minimize all active sheet objects on active sheet **
set s=ActiveDocument.ActiveSheet
objs=s.GetSheetObjects
for i=lbound(objs) to ubound(objs)
if objs(i).IsActive then objs(i).Minimize
next

I hope this helps.

Not applicable

I used sir pinongs' code as a basis:

you can try this:

Sub Test

set s=ActiveDocument.ActiveSheet

objs=s.GetSheetObjects

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

if objs(i).IsActive then

msgbox("Object Id: " & objs(i).GetObjectId)

ActiveDocument.Variables("vID").SetContent objs(i).GetObjectId,true

end if

next

End Sub

actually i just added a message box that will tell you the Id of the object that you selected and pass the Id to a variable vID(you can use this variable in your export code)..

Stick out tongue

beanmachine
Partner - Contributor III
Partner - Contributor III
Author

Thanks for that, pinongs et al.

I used your suggestions and got the result I wanted. Now I have one macro to maintain which knows which sheet it was called from and behaves accordingly.