Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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.
Your assumption is correct. How you define the objectname when calling the macro? It could be another simple macro that calls ExpressionSort() with parameter.
I'm just trying to pass the object name as a string in the macro call - so something like ExpressionSort("chartname").
Looks correct to me. Can you upload an example of your app?
Here's a sample QVW with my concepts in it.
See macro in the attached.
You can pass the parameter in a different way of course.
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.
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.
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
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.