Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make VBA function "VBA only" and disable it as UDF

I'm writing a VBA function which I want to be publically available in other VBA modules within the same document, however I don't want it to be available as a UDF (User defined function).

If I use the public access modifier however my function is also be available as a UDF-formula that can be called from the cells within the workbook. I don't want this.

Is there an access modifier or other way that can help me obtain this "VBA only" behaviour?

Kind regards

like image 225
Skifozoa Avatar asked Jun 22 '12 12:06

Skifozoa


People also ask

How do you stop a function in VBA?

Using Exit Sub Statement in VBA First, decide on which line you want to add the “Exit Sub”. After that, check the structure of the code that will get executed when you run the code. Next, enter the “Exit Sub”. In the end, it's better to have comment that describes why you are using the “Exit Sub” statement.

Can a function call itself VBA?

You cannot "call" a function. A function provides a result; you need to set some variable equal to your function. If you just need the code to run, and don't need it to provide you with a specific variable result, then make it a sub, and not a function.

Why is a UDF used in Excel macro?

A UDF cannot modify the formatting of a cell or workbook or move values around on a worksheet. Basically, UDF's enable you to create custom functions that act very similarly to the built-in functions that are included in every installation of Excel, such as SQRT, SUM, and MAX.


1 Answers

If you use Option Private Module in the module in which the function appears, the function can be declared as Public and used in any of your other modules within your VBA project, but won't be accessible by other applications or projects, including Excel itself.

like image 132
YowE3K Avatar answered Oct 06 '22 23:10

YowE3K