I need some help!!
I declared 4 variables as string file1, file2, file3 and file4
then I assign the value of each cell to the respective value
file1 = Cells(9, "C").Value ' Set the first file to attache
file2 = Cells(11, "C").Value ' Set the Second file to attache
file3 = Cells(13, "C").Value ' Set the Third file to attache
file4 = Cells(15, "C").Value ' Set the Fourth file to attache
Now I'm trying to attached the files to an email as an attachment like this:
.Attachments.Add (file2)
.Attachments.Add (file2)
.Attachments.Add (file3)
.Attachments.Add (file4)
It works well as long as there is a value in each cell. But if I choose not to put a value in anyone of the cell it doesn't work.
What I would like to have is to check each file# to see if there is a value and if yes to attached it to the email, if it's empty then move to the next one.
I tried:
For num = 1 To 4
filenum = file & num
If filenum <> "" Then
.Attachments.Add (CStr(file & num))
MsgBox (CStr(file & num)) ' just to debug
Else
End If
Next num
But i'm sure you guessed that it doesn't work as the (CStr(file & num)) return the file1 and not the actual path of the file.
Thanks in advance for your help!
I declared 4 variables as string file1, file2, file3 and file4
then I assign the value of each cell to the respective value
file1 = Cells(9, "C").Value ' Set the first file to attache
file2 = Cells(11, "C").Value ' Set the Second file to attache
file3 = Cells(13, "C").Value ' Set the Third file to attache
file4 = Cells(15, "C").Value ' Set the Fourth file to attache
Now I'm trying to attached the files to an email as an attachment like this:
.Attachments.Add (file2)
.Attachments.Add (file2)
.Attachments.Add (file3)
.Attachments.Add (file4)
It works well as long as there is a value in each cell. But if I choose not to put a value in anyone of the cell it doesn't work.
What I would like to have is to check each file# to see if there is a value and if yes to attached it to the email, if it's empty then move to the next one.
I tried:
For num = 1 To 4
filenum = file & num
If filenum <> "" Then
.Attachments.Add (CStr(file & num))
MsgBox (CStr(file & num)) ' just to debug
Else
End If
Next num
But i'm sure you guessed that it doesn't work as the (CStr(file & num)) return the file1 and not the actual path of the file.
Thanks in advance for your help!