How do I declare a global variable in VBA?

前端 未结 8 1086

I wrote the following code:

Function find_results_idle()

    Public iRaw As Integer
    Public iColumn As Integer
    iRaw = 1
    iColumn = 1
8条回答
  •  逝去的感伤
    2020-11-22 09:04

    If this function is in a module/class, you could just write them outside of the function, so it has Global Scope. Global Scope means the variable can be accessed by another function in the same module/class (if you use dim as declaration statement, use public if you want the variables can be accessed by all function in all modules) :

    Dim iRaw As Integer
    Dim iColumn As Integer
    
    Function find_results_idle()
        iRaw = 1
        iColumn = 1
    End Function
    
    Function this_can_access_global()
        iRaw = 2
        iColumn = 2
    End Function
    

提交回复
热议问题