Do Until loop with if statement
Sandy wrote:
Thanks for your response!
Note that if I try to use GoTo SKIP_FILE on an if
statement, the whole thing fails. The code is:
Public Function ExportToTemplates()
<snip
On Error GoTo SKIP_FILE
Set dbs = DBEngine.Workspaces(0).Databases(0)
<snip
FileName = Dir(DBPath & "Templates_Out\*.xls")
Do Until FileName = ""
'Put If "div" file language in here
If UCase(Left(FileName, 3)) = "DIV" Then GoTo SKIP_FILE
Does this line not work for you?
An identical functional way would be to have he
If UCase(Left(FileName, 3)) = "DIV" Then
and a corresponding 'End If' just above the SKIP_FILE line. Of course,
you might want to indent the lines within the IF - END IF.
Matthew
<snip
FilePathName = DBPath & "Templates_Out\" &
FileName
xl.Application.Workbooks.Open FilePathName
' get area code
<snip
FileCopy FilePathName, ls_destination
Kill FilePathName
SKIP_FILE:
<snip
FileName = Dir()
Loop
<snip
End If
End Function
Thanks again!
Sandy
-----Original Message-----
Sandy wrote:
I am looping through files in a directory with a Do
Until ... Loop. If there is a file name
with "div...".xls
in it, I need to skip it and go to the next file.
Any suggestions would be greatly appreciated!
Sandy
It's a bit hard to get specific without some of the code
you have
already written, but it might look something like this:
strFileName = <first filename
Do
If Left(strFileName,3) < "div" Then
<process file somehow
...
End If
strFileName = <set to next filename
Loop Until <condition
Hope this helps,
Matthew
.
|