【发布时间】:2021-08-07 19:14:12
【问题描述】:
我有以下代码,我可以循环遍历文件夹内的所有 .dwg 文件。
Private Sub CommandButton1_Click()
'open file to extract
Dim MyFolderext As String
Dim MyFileext As String
'ficheiro origem
MyFolderext = "C:\Users\abc\test"
MyFileext = Dir(MyFolderext & "\*.dwg")
Do While MyFileext <> ""
Application.Documents.Open MyFolderext & "\" & MyFileext
'check sub if not enough inputs were placed on the user console
check
'unlock drawing layers
ThisDrawing.Layers("MC_BLOCO_INFO_AREAS").Lock = False
ThisDrawing.Layers("MC_BLOCO_TEXTOS_COMERCIAL").Lock = False
ThisDrawing.Layers("MC_BLOCO_TEXTOS_INV").Lock = False
'sub of the program
program
MyFileext = Dir
Loop
'when finished
MsgBox "Done!"
'sub to clean to console for next operation
clean
End Sub
虽然它适用于文件夹内的所有文件,但我无法使其适用于子文件夹,我仍然需要过滤其中的一些。 所以我要问的是:您能帮我更改代码以打开母文件夹“C:\Users\abc\test”中的所有文件夹,但跳过文件夹“ignore”吗?
编辑: 我想出了这个,但仍然无法正常工作:
Sub FileSearch(ByRef Folder As Object)
Dim MyFileext As String
Dim File As Object
Dim SubFolder As Object
MyFileext = Dir(MainFolder & "\*.dwg")
Do While MyFileext <> ""
Application.Documents.Open MainFolder & "\" & MyFileext
For Each File In Folder.Files
programa
Next File
Loop
For Each SubFolder In Folder.SubFolders
If SubFolder.Name <> "extras" Then
FileSearch SubFolder 'Recursion
End If
Next SubFolder
End Sub
Private Sub CommandButton1_Click()
check
Dim MainFolder As Object
Set MainFolder = CreateObject("Scripting.FileSystemObject").GetFolder("C:\Users\abc\test")
FileSearch MainFolder
MsgBox "Done!"
clean
End Sub
【问题讨论】:
-
这能回答你的问题吗? Get list of sub-directories in VBA
标签: vba filter directory subdirectory autocad