Is it possible to declare a public variable in vba and assign a default value?

后端 未结 8 687
旧时难觅i
旧时难觅i 2020-12-09 01:33

I want to do this but it won\'t compile:

Public MyVariable as Integer = 123

What\'s the best way of achieving this?

8条回答
  •  隐瞒了意图╮
    2020-12-09 01:48

    This is what I do when I need Initialized Global Constants:
    1. Add a module called Globals
    2. Add Properties like this into the Globals module:

    Property Get PSIStartRow() As Integer  
        PSIStartRow = Sheets("FOB Prices").Range("F1").Value  
    End Property  
    Property Get PSIStartCell() As String  
        PSIStartCell = "B" & PSIStartRow  
    End Property
    

提交回复
热议问题