Solved Run Time Error - Cannot find file - Attaching to email

allen675

Member
Local time
Today, 06:46
Joined
Jul 13, 2022
Messages
124
Hi again!

Really not sure why I'm getting this message. I have various pieces of VBA code all pointing to this same document in my DB with no problems. Now I want to try and attach this file to an email I'm getting this error message. The file exists, the path hasn't changed!

This is the code:

Code:
Private Sub Command23_Click()
Dim oApp As New Outlook.Application
Dim oEmail As Outlook.MailItem
Dim fileName As String

'Preparing Spreadsheet to send to directors
'First select the tracker just created
fileName = Application.CurrentProject.Path & "\Tracker"

'Email result of spreadsheet just created
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
    .Recipients.Add "test@test.com"
    .Subject = "Tracker"
    .Body = "Please find attached this weeks Tracker"
    .Attachments.Add fileName
    .Display
End With

End Sub

Help most appreciated
 

Attachments

  • Error.PNG
    Error.PNG
    7.4 KB · Views: 134
The file
 
I know what your going to say, no extension!
Just added extension to code and it works!

Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
 
Just added extension to code and it works!

Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
I would sincerely doubt that, but you would have to show us the code to prove it. :)
 
Question then, elsewhere in my VBA code I have this file referenced but without the extension, why did it cause a problem here?
maybe it thinks that it is a folder.
a dot (.) as suffix can do?
 
Yep you are correct, my other code does include the file extension! Doh! 👍
Computers do not just change their mind (well except for Google minis', they have a mind of their own :( )
So unless something changes, it will produce the same result.
 

Users who are viewing this thread

Back
Top Bottom