Run-time error "Method "Add" of object "Attachments" failed"

Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
422
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Dear all,

I am trying to run a macro that sends out emails, however when I try to run it I keep getting this error unfortunately:

1642683535626.png


Can somebody please help me figure out why? I have tried setting source = ThisWorkbook.FullName (takes the current excel file I am typing in as an attachment) before and then typing EmailItem.Attachments.Add Source with no issues.

For some reason this gives me an error now with the debug highlighting EmailItem.Attachments.Add Source

Can somebody figure out why?

Would be immensely greatful!

Kind regards
Jyggalag
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Full code:

Sub SendEmail()

Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application

Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)

EmailItem.To = Join(Filter(Application.Transpose(Range("O2:O10")), " ", False), ";")
EmailItem.CC = "test2@mail.com"
EmailItem.BCC = "test3@mail.com"
EmailItem.Subject = "Test Email From Excel VBA"
EmailItem.HTMLBody = "Dear all,<br/>" & "<BR><BR>" & _
"text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text .<br/>" & "<BR><BR>" & _
Source = ThisWorkbook.FullName
EmailItem.Attachments.Add Source

EmailItem.Send

End Sub

Update: I also tend to get this error now:

1642683807794.png
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Apologies! Will make sure not to do this again.
 
Upvote 0
That isn't an error. It looks like you put a breakpoint there.
 
Upvote 0
I
That isn't an error. It looks like you put a breakpoint there.
I apologize for not understanding you completely, but what do you mean by breakpoint if I may ask?

I tried running the code again (after having saved the file of course) and now it gives this error:

1642685742317.png


When I try to debug, this gets highlighted:

1642685761180.png
 
Upvote 0
You definitely saved the workbook that has the code in it?

A breakpoint is a point you can set where the code will stop and wait for you to debug it. The little red dot in the margin is the indicator for it. You use f9 to set and clear them on any executable line of code.
 
Upvote 0
You definitely saved the workbook that has the code in it?

A breakpoint is a point you can set where the code will stop and wait for you to debug it. The little red dot in the margin is the indicator for it. You use f9 to set and clear them on any executable line of code.
Yes I did, and I still get this error :(

1642686431489.png


I have it saved in a subfolder, didnt create any issues before:

1642686469254.png
 
Upvote 0

Forum statistics

Threads
1,215,170
Messages
6,123,422
Members
449,099
Latest member
COOT

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