Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个单独的模块来声明公共变量
Public ws1, ws2 As Worksheet
在每个模块上,在每个过程中,我必须重复以下内容:
Set ws1 = Sheets("Sun") Set ws2 = Sheets("Moon")
...然后 - 编写代码。
那么,我可以在哪里以及如何设置这些变量,以便它们已经在每个模块、每个子或函数上设置 - 作为表太阳和月亮?
设置完成后,其他模块仍然可以使用它。所以我建议你设置它Workbook_Open。此外,您当前的代码没有ws1作为工作表进行标注,所以我建议您使用
Workbook_Open
ws1
Standard Module
Public ws1 As Worksheet, ws2 As Worksheet
ThisWorkbook Module
Private Sub Workbook_Open() Set ws1 = ThisWorkbook.Sheets("Sun") End Sub