下一步没有编译错误(但我俩都有。)

时间:2019-07-01 16:07:30

标签: excel vba

' 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。我知道这一定是我正在做的新手工作,但最近一两个小时我一直在对此进行研究。

非常感谢您的所有帮助!

1 个答案:

答案 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
相关问题