1

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

0

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I'm afraid that you and I are right. Excel can't handle it this way sice there is no something like a hyerarchy of who is parent of who then to prioritize calls since I am not using objects to create this functionality. I can't create wrapper functions since other people here at work may need to have my very own add-in to re-open the file and get the same results in which case I'd better choose to just pass my add-in around or improve the current one that everyone has! :/ hehe Thanks on taking a time to understand what my problem is.
0

This may help: Function Overloading and UDF in Excel VBA

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.