VBA global variables, multiple workbooks

前端 未结 4 1730
轻奢々
轻奢々 2021-01-14 19:08

I have a VB application, that uses some global variables to store data that is required by multiple forms and modules, this works fine. However if a user opens up another wo

4条回答
  •  终归单人心
    2021-01-14 20:10

    I think you could get the workbook name in runtime.

    So, a Collection probably will do the job.

    '//-- module --
    Public var As Collection
    
    Public Function SetVar(Value)
       If var Is Nothing Then
          Set var = New Collection
       End If
       var.Add Value, ThisWorkbook.Name
    End Function
    
    Public Function GetVar() As Variant
       If var Is Nothing Then
          GetVar = Null
       Else
          GetVar = var.Item(ThisWorkbook.Name)
       End If
    End Function
    

    Not sure if it'll work for your Addin though.

提交回复
热议问题