Can a worksheet object be declared globally in Excel VBA?

后端 未结 6 1375
余生分开走
余生分开走 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:38

    Your Worksheets are "Microsoft Excel Objects" defined in your VBA-Project-Explorer:

    Worksheet Properties editing

    In The Screen above i have named my Worksheet DataSheet, so now i can access it directly from within the code:

    Set SomeRange = DataSheet.Range("A3:B6")
    

    By Default your Worksheets will be named "Sheet1", "Sheet2", aso... depending on your language.

提交回复
热议问题