Search code examples
excelvbaconstants

Use Environ("LOCALAPPDATA") with a Public Const. (or an alternative solution)


I have been using the following VBA code

Public Const COSTER_FOLDER = "C:\Coster"

But this will no longer work when they shift the folder location.

The new Coster folder is Environ("LOCALAPPDATA") & "\Coster"

Is there a simple way to do this using a Constant or is there a better way?

Regards Peter


Solution

  • Here's another option. Remove the old definition, and use this.

    Public Function COSTER_FOLDER() As String
        COSTER_FOLDER = Environ("LOCALAPPDATA") & "\Coster"
    End Function
    

    Then you can use it the same way:

    Debug.Print COSTER_FOLDER & "\test.txt"