I am using the following snapshot of code to loop through files in a folder, it has a simple If to check if there are files in the folder then exits if there aren't. I've realised it does not require an End If at the end to compile correctly. However, I want to add a msgbox explaining why it has exited and to do so I need to introduce an End If to my code.
Why is that?
Original Code
If Len(strfilename) = 0 Then Exit Sub
Do Until strfilename = ""
'Do some stuff
strfilename = Dir()
Loop
With MsgBox
If Len(strfilename) = 0 Then
MsgBox ("No Files Found")
Exit Sub
Else
Do Until strfilename = ""
'Do some stuff
strfilename = Dir()
Loop
End If