vba - Excel: Search for all zip files inside a folder -


i have macro (loop through files in folder using vba?) looks inside folder zip files, problem last zip file has empty string name. how can avoid error.

the code macro:

sub loopthroughfiles()     ' define variables     dim file string, folder string      ' define working directory     folder = "c:\users\cportocarrero\desktop\curvas\"      ' define type of file search     file = dir(folder & "*.zip")      ' loop through files     while len(file) > 0         debug.print file         file = dir         msgbox file     loop end sub 

you have keep loop this:
- first call dir before loop, then
- while loop
- call dir should last command inside loop

file = dir(folder & "*.zip") while file <> ""     debug.print file     msgbox file     file = dir loop 

when dir returns empty string, means there no more matches.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -