Is it possible to write UDF in VBA that contains a period in a name?

Excel 2010 comes with some features that contain a period in their name. For example, STDEV.S and PERCENTILE.EXC

Is it possible to assign a name to my own function with a name like PERCENTILE.CUSTOM , using VBA?

For example, I would like to reference the following function using the formula =NAME.SUFFIX()

 Option Explicit Function NAMEdotSUFFIX() As Variant NAMEdotSUFFIX = 42 End Function 
+4
source share
2 answers

This is not possible from VBA. This MSDN article shows how to define a function in VBA and, in particular, this article sets out the rules for element names.

0
source

As @SiddharthRout has already suggested, external libraries have fewer restrictions than VBA when it comes to declaring function names, so periods are allowed in external names.

Despite the MSDN documentation, you can use some special characters in VBA identifiers, including UDF. Special characters may even be the first / only character in the identifier. Special characters will differ in their accessibility, according to the code page of the VBA and VBE project.

This is a great VBA feature:

 Public Function FooBar() FooBar = 5 End Function 

And can be used in an Excel formula:

 =Foo路Bar() 5 

Similarly, this function pearl uses inextricable space as the name of the function:

 Public Function  () = 6 End Function 

But, although the function with NBSP is valid, unfortunately, it cannot be used in an Excel formula.

Can be used:

 Public Function() 路 = 5 End Function 

BONUS HACK

Someone forgot to tell the Enum team about identifier rules. Although Enums cannot be used in Excel formulas, you can use any character other than carriage returns or square brackets inside square brackets as a name or a member of an enumeration.

This is absolutely true of VBA:

 Enum [Foo : Bar = 5 : End Enum] [.B!ar"] = 6 End Enum 

And the beautiful VBE printer turns it into this unrivaled mess:

 Enum Foo : Bar = 5 : End Enum [.B!ar"] = 6 End Enum 
+3
source

All Articles