excel VBA忽略目录中的特定文件夹/文件

时间:2013-11-26 05:23:42

标签: excel vba

我已经制作了一个宏来读取1个文件夹中的所有文件夹 - 路径如:

C:\folder\folder\

结果

C:\folder\folder\design

C:\folder\folder\sheetA

我必须添加一个条件:如果C:\ folder\folder\design,宏将继续而不读取设计文件夹中的内容。

在文件夹前添加更多dir,因此主路径变为:C:\folder\*并忽略文本文件

说明我的问题的图表:

enter image description here

我的代码:

Sub readDir()

Const sMainPath As String = "C:\Users\User\Desktop\excel\testing\"
Dim sMain As String, sPathSeek As String, sPathMatch As String
Dim i As Integer, sFolders As String, x As Integer, n As Integer
i = 0
x = 2
sPathSeek = sMainPath

sMain = Dir(sPathSeek, vbDirectory)

    Do While Len(sMain) > 0
        If Left(sMain, 1) <> "." Then

            mainDir = sMainPath & sMain & "\"

            'Call readFolder(mainDir)

        End If
        sMain = Dir

    Loop
End Sub

1 个答案:

答案 0 :(得分:1)

评论,重新发布作为答案,因为它适合您:

If mainDir = "C:\folder\folder\design" Then 
   'Do Nothing 
Else 
   'Do stuff 
End If