VBA excel Overload another add-in function
Question! I have an add-开发者_运维技巧in we created at work, say foo.xla, and it has a function foo_sub(arg1).
Now, I want to improve the way that foo_sub(arg1) behaves but withour editting the original add-in code, since as soon as they update it, I must migrate my code from the old add-in to the newer.
Is there a way I could write foo_sub(arg1) in a different add-in, say fee.xla, so that every time I call foo_sub from a worksheet the one that get's called is the one I wrote?
Thanks in advance
I had a lot of similar issues when trying to overload a constructor in VBA in Excel.
However, I think your problem is a little different. You're not necessarily trying to overload the function by providing a separate method with the same name and different parameters; you're trying to add a method with the exact same name, return type, and parameters and figure out a way to have Excel call your function rather than that of the add-in.
I'm not positive, but I don't think this is possible in Excel VBA. If you try to call a function that's defined in multiple places, it will get confused and tell you that it doesn't know which one to call.
You might create a wrapper function called my_foo_sub(arg1)
which has custom code in it. Then, if you need to switch to the new foo_sub(arg1)
when the .xla
file is updated, you could just comment out your custom code and add a call to foo_sub(arg1)
. This is far from ideal, but it might help.
This may help: Function Overloading and UDF in Excel VBA
精彩评论