Can a worksheet object be declared globally in Excel VBA?

后端 未结 6 1415
余生分开走
余生分开走 2021-01-05 02:32

I\'m refactoring a number of modules in an Excel 2003 workbook and the same set of worksheets are declared in each procedure in each module; I\'d like to just declare them o

6条回答
  •  情歌与酒
    2021-01-05 02:56

    Or if you do not want to use the Excel Event, you can also declare your worksheet publicly, then create a sub to set value for it. Call that sub at the beginning of each sub to initialize the value. (I did this from orwell's answer.)


    Public WSRawData As Worksheet
    

    Public Sub RawDataWSInit()
    
    Set WSRawData = Worksheets(RawData)
    
    End Sub
    

    Sub Main()
    
    Call RawDataWSInit
    
    End Sub
    

提交回复
热议问题