PDA

View Full Version : Cannot Find This File



basicintern
07-01-2014, 10:44 AM
I am using a Dir() function to loop through files in a folder and attach them to an Outlook email:


report_file = Dir(report_path & folder1)


Do While Len(report_file) > 0
.Attachments.Add report_file
report_file = Dir
Loop


The Dir() function is finding the first file in the folder and correctly saving it to the report_file variable but I get the following error once I try to attach it: "Cannot find this file. Verify the path and file names are correct." The path and file names must be correct since the code found the file itself using the path name. But then it suddenly can't find the file anymore once it's time to attach it. I tried both moving this folder to a local drive and erasing the folder and recreating it entirely but neither worked. I am so lost!

basicintern
07-01-2014, 11:02 AM
Okay this was a really stupid question. I needed the entire file name with the path and Dir() just produces the file name. Sorry about that...

westconn1
07-01-2014, 01:55 PM
try
.Attachments.Add report_path & folder1 & "\" & report_file


not sure you need folder1 or the \, your code does not make clear the content of your variables