Error in VBA-code for send mail with Attached file using outlook.

KlausW

Active Member
Joined
Sep 9, 2020
Messages
458
Office Version
  1. 2016
Platform
  1. Windows
Hi, I use this VBA code to send mail with Attached file using outlook. But I for this error message see the attachment, someone who can help.
Any help will be appreciated.
Best regards Klaus W

VBA Code:
Option Explicit

Private Sub Send_Email_to_an_Address_in_Cell()

Dim MyOutlook As Object
Set MyOutlook = CreateObject("Outlook.Application")

Dim MyMail As Object

Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = Range("a17").Value '& "; " & Range("a18").Value & "; " & Range("a19").Value & "; " & Range("a20").Value

MyMail.Subject = Range("a24").Value
MyMail.Body = Range("a25").Value & vbNewLine & vbNewLine & Range("a26").Value & vbNewLine & _
        Range("a27").Value & vbNewLine & Range("a28").Value & vbNewLine & Range("a28").Value & vbNewLine & _
        Range("a29").Value & vbNewLine & _
        Range("a30").Value

Attached_File = Range("a31").Value
MyMail.Attachments.Add Attached_File

MyMail.Send

End Sub
 

Attachments

  • 2023-05-18 (1).png
    2023-05-18 (1).png
    123.7 KB · Views: 18

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi there...

What happens if you add this line to the beginning...

VBA Code:
Dim Attached_File As Outlook.Attachments
 
Upvote 0
Rory is correct... Only realised now that the Attached file is referring to a string in a range...
 
Upvote 0
Hi RoryA
Thanks allot its works as it shoud. Have a great day,
Best regards from Denmark. Klaus W
 
Upvote 0

Forum statistics

Threads
1,224,802
Messages
6,181,048
Members
453,014
Latest member
Chris258

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top