Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Passing object id to macro

I have a simple sorting macro like this:

Sub ExpressionSort

Set chart = ActiveDocument.GetSheetObject("chartname")

    prop = chart.GetProperties

    If prop.Dimensions(0).SortCriteria.SortByExpression = 1 Then

        prop.Dimensions(0).SortCriteria.SortByExpression = -1

    Else   

        prop.Dimensions(0).SortCriteria.SortByExpression = 1

    End If

    chart.SetProperties prop

End Sub

I'd like to reuse this for different objects, but I can't seem to pass the object id along through a parameter.  I would expect it to be something like this

Sub ExpressionSort(objectname)

Set chart=ActiveDocument.GetSheetObject(objectname)

But that doesn't work at all. 

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Here is another one.  Separate buttons per chart, parameter is passed through a variable, one macro.  I didn't remove other macros but they are not needed.

See if it fits your better.

View solution in original post

10 Replies
Anonymous
Not applicable
Author

Your assumption is correct.  How you define the objectname when calling the macro?  It could be another simple macro that calls ExpressionSort() with parameter.

Not applicable
Author

I'm just trying to pass the object name as a string in the macro call - so something like ExpressionSort("chartname").

Anonymous
Not applicable
Author

Looks correct to me.  Can you upload an example of your app?

Not applicable
Author

Here's a sample QVW with my concepts in it.

Anonymous
Not applicable
Author

See macro in the attached.

You can pass the parameter in a different way of course.

Not applicable
Author

That helps a little in that I could then create a bunch of little macros instead of having to reproduce the entire macro several times, but I was hoping I could avoid having to create macros hardcoded to specific objects.

Anonymous
Not applicable
Author

Yes, last time I did it, it was a bunch of little macros.

Maybe there is a better way.  In my case I was satisfied with this approach.


Not applicable
Author

While it's not ideal for me, it's better than what I had.  It's good to know I can at least call another macro with an object id in the parameter.

Thanks

Anonymous
Not applicable
Author

Here is another one.  Separate buttons per chart, parameter is passed through a variable, one macro.  I didn't remove other macros but they are not needed.

See if it fits your better.