Avatar of AFGPHXExcel
AFGPHXExcel
 asked on

Mail attachment an Excel file in VBA

I am trying to attach a file I have saved to the desktop to an Outlook Object. Outlook seems to ignore the file though. Any help would be much appreciated.

v_WksFldrDest = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator

EmailAttachDest= v_WksFldrDest & v_TempFileName

            Dim OutApp As Object
            Dim OutMail As Object
            Dim strbody As String
       
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
               
                strbody = Range(ReviewerName & "ReqBy_EmailTxt").Value & vbNewLine & vbNewLine & _
                        "Please reply to: " & Range(ReviewerName & "ReplyTo_Name").Value & _
                            " at " & Range(ReviewerName & "ReplyTo_Email").Value & " and CC to " & Range(ReviewerName & "ReplyCC_Email").Value


            On Error Resume Next
            With OutMail
                .To = Range(GKName & "_GatekeeperEmail").Value
                .CC = Range(ReviewerName & "ReqCC_Email").Value
                .BCC = ""
                .Subject = v_TempFileName
                .Body = strbody
                'You can add a file like this
                .Attachments.Add (EmailAttachDest)
                '.Send or use
                .Display
            End With
            On Error GoTo 0
       
            Set OutMail = Nothing
            Set OutApp = Nothing
Microsoft ExcelOutlook

Avatar of undefined
Last Comment
Arno Koster

8/22/2022 - Mon
AFGPHXExcel

ASKER
As a note. I am getting an error saying it cannot find the file even though the address for EmailAttachDest is correct and the file is on the desktop.
Anil

The reference for Excel and Sending mail is from Ron BRuin MVP:

http://www.rondebruin.nl/sendmail.htm

Hope this helps.

A>
Arno Koster

If I run it the variable 'EmailAttachDest' has the value "\[filename]" : no path is added.
Have you verified that the actual path to your desktop is included at your workplace ?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Arno Koster

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question