Home > Enterprise >  Parse Backwards in VBA for a Valid Function Name
Parse Backwards in VBA for a Valid Function Name

Time:07-31

Update

This excel-names project is contained in VBA, and it might offer some insights on the validity of various names in Excel and VBA. Unfortunately, it cannot fully guarantee validity here:

  • Names_IsValidName(sNameToTest As String) As Boolean

    Check if the name is valid:

    • true: Excel name is probably valid

    • false: Excel name is for sure not valid

Additionally, the XLParser project in C# specifies here many of the special operators and characters in Excel formulae.

However, I am still trying to determine exactly how these might apply to my solution, which must be contained in VBA.


Background

I am writing in VBA a lightweight parser for Excel formulae, which assumes that any input is syntactically valid (as validated by Excel). My goal is to properly pinpoint an entire function call within a formula.

For this, I need a function FindValidName(). This function accepts a String ending at the open parenthesis (() of a function call, and searches backward to locate the beginning of the valid formula name; or it returns -1 if no such name is found.

Question

What are the syntactic criteria for a valid function name, accessible in an Excel formula? This does not encompass every function like VBA.Mid() accessible in VBA, since those are not accessible in Excel itself. Neither does it encompass user-defined functions (UDFs) in VBA, which are accessible in Excel and have their nomenclature defined here.

More generally, how might one algorithmize in VBA a backwards search by FindValidName() from the end of the name? Mind you, this must encompass

  • Related