So far I've been declaring my constants in the "Main" module for my workbook, below the "Option Explicit" but above the "Sub DoTheWork()."
Do public constants have to be declared outside the sub like this or can they be declared at any point in the script?
Examples:
Current method:
Option Explicit
Public Const Example as Integer = 1
Private Sub DoTheWork(ByVal Target as Range)
Questionable method:
Option Explicit
Private Sub DoTheWork(ByVal Target as Range)
Public Const Example as Integer = 1
Dim Example2 as Integer
Example2 = 2
Is the second method viable? Is it bad practice? Is it worth trying?
Public Const Example as Integer = 1placement is invalid in the 2nd snippet.Public... but your question is about public constants.PublicorPrivate- the compiler will not allow it. Any constant declared within a method is restricted in scope to only that method. learn.microsoft.com/en-us/office/vba/language/concepts/…