昏暗并在所有模块excel vba中设置变量

时间:2022-11-25 10:02:02

I have many projects where I have the same variables across multiple modules. In each module I dim and set the variables and each time they are the same variable type and have the same value. How do I dim and set variables across an entire project/workbook?

我有很多项目,我在多个模块中有相同的变量。在每个模块中,我调暗并设置变量,每次它们是相同的变量类型并具有相同的值。如何在整个项目/工作簿中调暗和设置变量?

Ex: (I have many modules in a workbook where I have had to repeat all of the following along with many other similar variables that do not change across modules)

例如:(我在工作簿中有许多模块,我必须重复以下所有以及许多其他类似的变量,这些变量不会在模块之间发生变化)

Sub PullSFAFiles()
Dim Wb                          As Workbook
Dim WsSFAFiles                  As Worksheet
Dim WsAllCourses                As Worksheet
Dim rngAllCourses               As Range
Dim rngCourse                   As Range
Dim LoSFAFiles                  As ListObject
Dim rngPreviousFiles            As Range
Dim rngRemoveLines              As Range

Dim strCourse                   As String
Dim strApp                      As String
Dim strPeCFldrPath              As String
Dim strFileLocation             As String
Dim strFileNm                   As String
Dim objFile                     As Object

Dim intSFARow                   As Integer
Dim intCourseRow                As Integer
Dim intPFilesRow                As Integer
Dim dtLastUpdate                As Date
Dim intNumRemove                As Integer

Set Wb = ThisWorkbook
Set WsSFAFiles = Wb.Sheets("sfafiles")
Set WsAllCourses = Wb.Sheets("allcourses")
Set rngAllCourses = WsAllCourses.Range("tblAllCourses[CourseName]")
Set LoSFAFiles = WsSFAFiles.ListObjects("tblSFAFiles")

strEBTypeFolder = "Exercise Booklet"
strEBfiletype = "EB"
strCISTypeFolder = "Classroom Information Sheet"
strCISfiletype = "CIS"
intCourseRow = rngCourse.Row - 1
strCourse = rngCourse.Value
strApp = WsAllCourses.Range("tblallcourses[application]").Rows(intCourseRow)
strPeCFldrPath = "\\Cx138\training\Live\Credentialed Trainers\"
strEBFileLocation = strApp & "\" & strTypeFolder & "\" & strCourse & "_" & strEBfiletype & "*" & ".pdf"
strEBFileNm = Dir(strPeCFldrPath & "\" & strEBFileLocation)
strCISFileNm = Dir(strPeCFldrPath & "\" & strCISFileLocation)

1 个解决方案

#1


3  

Replace variable declaration Dim with Public. Thus:

将变量声明Dim替换为Public。从而:

Public rngCourse as Range

Public strCourse As String

Declare them at module level.

在模块级别声明它们。

#1


3  

Replace variable declaration Dim with Public. Thus:

将变量声明Dim替换为Public。从而:

Public rngCourse as Range

Public strCourse As String

Declare them at module level.

在模块级别声明它们。