我继承了一个宏,需要进行更新,请多多包涵。
Public Const strSourceFolder1 As String = "\\File_Path\Sub_Folder2"
Public Const strSourceFolder2 As String = "\\File_Path\Sub_Folder1"
我有8个以上的字符串。我想将它们放入一个数组,以便在整个过程中都可以引用。这可能吗?形成阵列会是什么样子? “ File_Path”是一个包含要由宏操作的文档的文件夹的位置,我的目标只是将源文件夹更新为一组文件夹。
我尝试了FoldersArray,但是当我在宏的这一部分中引用它时,类型却不匹配:
Private Sub GetFileName()
Dim wb As Workbook
Dim ws As Worksheet
Dim FileName As String
Dim Path As String
Dim lngRow As Long
Set wb = ActiveWorkbook
Set ws = ActiveSheet
lngRow = 2
Path = FolderArray & "*.*"
FileName = Dir(Path, vbNormal)
Do Until FileName = ""
Application.DisplayAlerts = False
Sheet1.Cells(lngRow, 1).Select
Sheet1.Cells(lngRow, 1) = FileName
Call MainExtractData(FileName, lngRow)
lngRow = lngRow + 1
FileName = Dir()
Loop
End Sub
答案 0 :(得分:1)
创建一个函数以返回您的文件夹集:
Function FolderArray()
Dim folders(1 to 8) As String
folders(1) = "\\File_Path\Sub_Folder2"
'....
folders(8) = "\\File_Path\Sub_Folder9"
FolderArray = folders
End Function