1

I have some constants declared in my VBA code as:

global const variable = value

These declarations are working properly, by which I mean they don't cause an error and the constants are used in other modules without error.

In reviewing the scope of my variables, I've looked at the Microsoft documentation to ensure that I'm doing it right. But lo and behold, I find that Microsoft doesn't even define global as a keyword! The official list of keywords for VBA does not include global:

Furthermore, the syntax for the const statement, given at:

is:

[ Public | Private ] Const constname [ As type ] = expression

which does not allow global as a modifier. This should mean that my declarations should be throwing a compiler error.

Moreover, three Microsoft pages about scope in VBA do not include the word "global" anywhere in their text:

I found one page of Microsoft documentation that refers to a keyword global, which is in the context of defining namespaces:

Because of that, the list of VBA keywords linked above is wrong for not including global.

There is a Stack Overflow answer that states, "Public and Global are nearly identical in their function, however Global can only be used in standard modules, whereas Public can be used in all contexts (modules, classes, controls, forms etc.) Global comes from older versions of VB and was likely kept for backwards compatibility, but has been wholly superseded by Public.":

And there is another Stack Overflow answer that describes the keyword global as "now deprecated, but still valid":

If those answers are correct, then I should change my code to replace global with public. But is there some documentation of the deprecation of global and the fact that it actually does still remain as a working keyword?

NewSites
  • 1,402
  • 2
  • 11
  • 26
  • If you're asking for documentation, that's off-topic for SO. And yes, the answers you link to are correct. – BigBen Oct 01 '21 at 12:11
  • Where is the place to ask for documentation? – NewSites Oct 01 '21 at 12:14
  • I'm not sure but see point 4 of [on topic](https://stackoverflow.com/help/on-topic). – BigBen Oct 01 '21 at 12:16
  • 2
    Just a quick comment to say that while BigBen is right, you presented your question well - I wish more people would! – CallumDA Oct 01 '21 at 12:17
  • 1
    I'm not sure you're even going to find documentation about this. There are other instances of deprecated yet still valid, e.g. the `Buttons` collection within the Excel VBA Object Model. Side note, I'd take MSFT docs with a grain of salt as they can have ... issues. – BigBen Oct 01 '21 at 12:20
  • 1
    Another side note, two of your links are VB.Net, not VBA. – BigBen Oct 01 '21 at 12:24
  • 1
    Finding VB.NET documentation when looking for VBA documentation does seem to happen quite often. Even MS is confused by them, it seems. – FreeMan Oct 01 '21 at 12:45

0 Answers0