在目录中排除文件

时间:2015-08-25 18:11:15

标签: excel-vba vba excel

我需要从DIR查找中排除文件。原因是Macro用完该文件并在其他文件中查找信息。有什么想法吗?

Sub button1_Click()
    Dim fn As String
    Dim rng As Range
    Dim myDir As String
    Dim fDir As String

    myDir = "C:\Users\boughtond\Desktop\PFS Macro\"
    fDir = Dir(myDir & "*.xlsm")

    Do While fDir  ""
        Workbooks.Open (myDir & fDir)

        For x = 9 To 108
            Workbooks(fDir).Activate
            If Cells(x, 1).Value = "O" Then
                fn = Cells(x, 2).Value
                Range(Cells(x, 2), Cells(x, 13)).Select
                Selection.Copy
                Windows("NAMC EIS PFS_All Shops.xlsm").Activate
                With Worksheets("Master").Range("A8:A1048576")
                    Set rng = .Find(What:=fn, LookIn:=xlValues)
                    If rng Is Nothing Then
                        ActiveSheet.Unprotect "eispfs"
                        Range("A1048576").End(xlUp).Offset(1, 0).Select
                        Selection.PasteSpecial
                    Else
                        MsgBox ("Found this sh*t" & Chr(10) & x)
                    End If
                End With
            Else
            End If
            'MsgBox x
            'x = x + 1
        Next x

        fDir = Dir()
    Loop

End Sub

忽略MSGBOX,因为我用来验证循环是否正常工作。 " NAMC PFS_All shops.xlsm"在同一个目录中,宏从它运行。我需要从查找中排除它。我也无法将其从文件夹中分离出来。

有什么建议吗?感谢您抽出宝贵时间。

0 个答案:

没有答案