Hello everyone.
I have learned VBA thru experience and I am not familiar with resolving issues when it comes into theory.
I have created a file that sends approx 200 emails. Before clicking the send button I want to verify that the user has entered the correct name of the file and the correct path..
The below macro is running OK ( with some modifications ) for one single file but I want it to work for all 200 files.
If I use DO UNTIL loop the loop becomes infinite, with the DO WHILE loop I am not getting the results I want as it shows that all files exists even I have a mistake.
Thanks a lot.
Sub check_files_exist()
'
' check_files_exist Macro
'
'DECLARATIONS
Dim myfile As String
Dim mypath As String
Dim filename As String
Dim x As Integer
'WHERE TO START FROM SINCE MY FIRST LINE WITH DATA IS NUMBER 2
x = 2
'START THE LOOP
Do While Sheet1.Cells(x, 1) <> ""
path = Sheet1.Cells(x, 4)
filename = Sheet1.Cells(x, 3)
myfile = path + filename
If Dir(myfile) <> "" Then
MsgBox "ALL FILES EXIST"
Else
MsgBox "CHECK THE FILES"
End If
Loop
End Sub
I have learned VBA thru experience and I am not familiar with resolving issues when it comes into theory.
I have created a file that sends approx 200 emails. Before clicking the send button I want to verify that the user has entered the correct name of the file and the correct path..
The below macro is running OK ( with some modifications ) for one single file but I want it to work for all 200 files.
If I use DO UNTIL loop the loop becomes infinite, with the DO WHILE loop I am not getting the results I want as it shows that all files exists even I have a mistake.
Thanks a lot.
Sub check_files_exist()
'
' check_files_exist Macro
'
'DECLARATIONS
Dim myfile As String
Dim mypath As String
Dim filename As String
Dim x As Integer
'WHERE TO START FROM SINCE MY FIRST LINE WITH DATA IS NUMBER 2
x = 2
'START THE LOOP
Do While Sheet1.Cells(x, 1) <> ""
path = Sheet1.Cells(x, 4)
filename = Sheet1.Cells(x, 3)
myfile = path + filename
If Dir(myfile) <> "" Then
MsgBox "ALL FILES EXIST"
Else
MsgBox "CHECK THE FILES"
End If
Loop
End Sub