' Loop through filenames and return within an array
For Each MyFile In MyFiles
If InStr(1, MyFile.Name, FileExt) <> 0 Then
Dim toSplitFileName As Variant
toSplitFileName = Split(MyFile.Name, "-")
For Each dept In deptCodes
MsgBox ("True")
If dept = toSplitFileName(3) Then
Next dept
Result(i) = MyFile.Name
i = i + 1
End If
Next MyFile
该错误发生在“对于deptCodes中的每个部门”
我来自PHP的背景,正在尝试学习VBA。我知道这一定是我正在做的新手工作,但最近一两个小时我一直在对此进行研究。
非常感谢您的所有帮助!
答案 0 :(得分:0)
我认为您需要这个。假设Result
声明正确。
Dim toSplitFileName As Variant
For Each MyFile In MyFiles
If InStr(1, MyFile.Name, FileExt) <> 0 Then
toSplitFileName = Split(MyFile.Name, "-")
For Each dept In deptCodes
MsgBox ("True")
If dept = toSplitFileName(3) Then
Result(i) = MyFile.Name
i = i + 1
End If
Next dept
End If
Next MyFile