Late Binding Global Variables?

后端 未结 2 2003
独厮守ぢ
独厮守ぢ 2021-01-21 01:27

I\'m using VBA for Excel. From my understanding, global variables need to be declared outside of any subs. That\'s the only way they can be accessed by all subs.

At th

2条回答
  •  时光取名叫无心
    2021-01-21 01:59

    Global variables are really not needed and should be avoided. However, if you have decided to use them for a your own reasons, you can put them in the Workbook_Open event:

    Option Explicit
    
    Dim Dic1 As Object
    Dim Dic2 As Object
    
    Private Sub Workbook_Open()
    
        Set Dic1 = CreateObject("Scripting.Dictionary")
        Set Dic2 = CreateObject("Scripting.Dictionary")
    
    End Sub
    

    Thus, it would create the object every time the workbook is opened.

提交回复
热议问题