我有一个宏(Loop through files in a folder using VBA?),它在文件夹中查找 zip 文件,但问题是最后一个 zip 文件有一个空字符串作为名称。我怎样才能避免这个错误。
宏的代码:
Sub LoopThroughFiles()
' Define variables
Dim file As String, folder As String
' Define working directory
folder = "C:\Users\cportocarrero\Desktop\Curvas\"
' Define type of file to search for
file = Dir(folder & "*.zip")
' Loop through all the files
Do While Len(file) > 0
Debug.Print file
file = Dir
MsgBox file
Loop
End Sub