In this article, we will see how to use a User Defined Function (UDF) defined in another workbook.
For this example, we have created a UDF “ReverseText” in “Reversing Characters In String.xlsm” workbook.
Raw data consists of sample text data in “MainFile”.
We want to reverse the sample text using the UDF “ReverseText” from “Reversing Characters In String.xlsm”.
We can use a User Defined Function (UDF) from another workbook like this:
=OtherWorkbookFullName!FunctionName(CellReference)
To use the UDF “ReverseText” in “MainFile”, we also have to define the full file name, along with an extension followed by an exclamation mark (!) in front of the UDF. So the Function will be like this:
='Reversing Characters In String.xlsm'!ReverseText(C11)
Note: If name of the file containing the UDF features space characters then we should enclose the file name within single quotes (‘).
We can also convert the file containing the User Defined Function to Add In. Then add that Add In with the Excel Application.
To create Add In and use Add In, Go to Question 1
Please follow below for the code
'Code in other workbook Option Explicit Function ReverseText(text As String) As String 'Reversing the text ReverseText = StrReverse(text) End Function
If you liked this blog, share it with your friends on Facebook. Also, you can follow us on Twitter and Facebook.
We would love to hear from you, do let us know how we can improve our work and make it better for you. Write to us at info@exceltip.com
The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.
This works perfectly. Thanks.
hi
this is giving me a #NAME error.
I know this is too late to reply, but still this would help others who see this post.
This works only if the workbook containing the UDF is open, in case if it is closed, you should mention the file path along with its name. Practically it won't work until you don't open the workbook containing the UDF.