Using a User Defined Function (UDF) from another workbook using VBA in Microsoft Excel

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”.

ArrowRawData

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 (‘).

ArrowOutputData

 

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

Users are saying about us...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

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.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube