我有很多项目,我在多个模块中拥有相同的变量。在每个模块中,我调暗并设置变量,每次它们是相同的变量类型并具有相同的值。如何在整个项目/工作簿中调暗和设置变量?
Ex :(我在工作簿中有很多模块,我必须重复以下所有内容以及许多其他类似的变量,这些变量不会在模块之间发生变化)
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)
答案 0 :(得分:3)
将变量声明Dim
替换为Public
。因此:
Public rngCourse as Range
Public strCourse As String
在模块级别声明它们。