Why can't I use the “Any” as a name in VBA?

后端 未结 2 1976
情歌与酒
情歌与酒 2021-01-13 01:28

While trying to define an Any() function like python\'s, I found that I couldn\'t name anything \"Any\".

Attempting to name a Function, Sub, Const

2条回答
  •  鱼传尺愫
    2021-01-13 02:07

    VBA (Visual Basic for Applications) is not VB.NET, even though they share the same "Visual Basic" monikor and a similar syntax. (The linked documentation is for VB.NET, not VBA.)

    VB6 and VBA in Microsoft Office (eg. Access, Excel) handles Any as a reserved word, and it cannot be used as an identifier:

    You might also encounter errors if you use a reserved word to name a control, an object, or a variable. The error messages you receive don't necessarily tell you that a reserved word is the cause of the problem.

    In VB.NET, however, there is no problem using Any as a variable name or other identifier:

    Dim Any as String = "Hello world!"    'works just fine in VB.NET
    

提交回复
热议问题