I put my macros in library ‘explore’ rather than in ‘Standard’ but runMacro() defaults to ‘Standard’ and I’ve yet to find the syntax of a call to get runMacro() to recognize my parameter and accept it as libName, the library to search for a matching function.
I’m uploading an example where you’ll find several of my attempts in function ‘_rangeWalkFn’. you will also see where I hard coded ‘explore’ in runMacro() while commenting out the ‘Standard’ line. with ‘explore’ set as libName the functions under the buttons run. With libName = Standard they don’t.
All suggestions welcome.
Thanks,
Mike
explorationsMini.ods (47.8 KB)
Hi. I’m not certain what the context is for what you are doing. But it sounds like you know you will have your macros in the ‘explore’ library. If that is the case, I guess I don’t see why you aren’t just calling explore.myMacro() rather than using runMacro(), if you don’t need to change the library at runtime.
The dot separator will access a macro by name, looking first for a library in the closest scope. So, if you have a MyMacros library called Library1 with a macro Main and your spreadsheet file has a library called Library1 with a macro Main, then within other macros in your spreadsheet file, Library1.Main will call the Main macro in Library1 of your spreadsheet. Rename that macro to MainX, and now Library1.Main will run the Main macro in Library1 under MyMacros.
You can also include the module name, like Library1.Module1.Main . Be aware that this is a selector rather than a specifier. That is, if you call Library1.Module2.Main and there is no such thing, Library1.Module1.Main will execute if it exists!!, and here the closest scope wins out…so even if there is a MyMacros Library1.Module2.Main exactly like you called the non-matching but closer-scoped Library1.Module1.Main will execute.
Thanks Joshua.
That’s good information but to apply it would break my usage. I use runMacro() in rangeWalkFn() to apply a function to all the cells in a range or ranges as needed. Often cells have properties that cellRange and cellRanges don’t address.
Good thinking though.
Be well,
Mike
Right, you do need to change…well, not the library, but the macro name…at runtime.
So, are you saying that if you pass the library name “explore” to
Function runMacro(funcName As String, Optional inpParams As Variant, Optional libName)
(with runMacro
not hotwired) as libName it doesn’t work, but if you set libName within runMacro
then it does?
Using your example sheet,
Sub Hello(Value)
MsgBox Value
End Sub
Sub RunHello
runMacro("Hello",Array("a",2,3),"explore")
End Sub
in a module under ‘explore’ works, or doesn’t exactly as I would expect, with runMacro set to default to ‘Standard’
Can you explain what isn’t working in a different way?
Bless you my man. Your simple Hello showed me the error of my ways. I copied your code into my program, reset runMacro() to default to Standard and called RunHello from a menu. With Standard as the default my menus become endless loops. I killed LOCalc to get out of that. I then put RunHello before the loop in the menu and saw it run which caused me to take another look at what I’ve written. As I’ve used rangeWalkFn() in almost every routine that I put in the menus, those being demonstrations of what I’m trying to learn, I put “explore” in _rangeWalkFn() where runMacro() is called. I hadn’t considered that runMacro() in the menus didn’t go through _rangeWalkFn() even though most of the routines in the menu did have calls to rangeWalkFn(). Prior to the menus I had buttons that called routines directly that would run fine if runMacro() defaulted to “explore” and not at all if Standard was the default since none of the code was in Standard. When RunHello() ran while Standard was the default It finally dawned on me that the menus needed to say runMacro( fName, Array( inpParams ), “explore”), making it so made the menus work as well as the buttons making direct procedure calls.
Though I’m accustomed to being in public with egg on my face, it’s not one of my favorite experiences, none the less it does give me a chance to laugh at my self.
Again thank you for your insight and I’ll give you the solution.
Be well,
Mike McClain
Anytime I post a new question on AskLO, I expect to be humbled, but I just count it as “a new set of eyes.” Anyway, your project seems fascinating even if I have no clue what it really does. I’ll assume it’s a time machine!
The example I posted in the first segment of this page is stripped down but the whole point is to get a better grip on cell, cellrange and cellranges functionality, including borders, a couple of charts and miscellaneous things that peak my curiousity.
I ported my stock tracker from Excel to LO Calc some 15 years ago and mostly have used it untouched until recently I thought to speed it up. I’m basically having to relearn LO basic hence the birth of explorations.ods.
I’ll gladly post the whole thing if you’re interested but assure you my programming style is nothing to brag about.
I wouldn’t call it a time machine but grant that it does consume a lot of time.
Be well,
Mike