Excel VBA Sending Outlook Email but cannot clear the previous attachments!

USAMax

Well-known Member
Joined
May 31, 2006
Messages
846
Office Version
  1. 365
Platform
  1. Windows
My user wants to look at every email before it goes out so she needs the .Display option. The problem is that I cannot clear the attachments between emails.

Code:
                 Set OutApp = CreateObject("Outlook.Application")
                 Set OutMail = OutApp.CreateItem(0)

                 On Error Resume Next
                 With OutMail
                     Debug.Print wsEmail.Cells(lngEmlRow, intEmail)
                     .To = "testuser@domain.com"
                     .CC = ""
                     .BCC = ""
                     .Subject = strSubject
                     If InStr(1, wsEmail.Cells(lngEmlRow, intCustName), " ") > 0 Then
                        .Body = "Hello " & Trim(Left(wsEmail.Cells(lngEmlRow, intCustName), _
                                InStr(1, wsEmail.Cells(lngEmlRow, intCustName), " "))) & "," & vbLf & varBodyText.Value
                     Else
                        .Body = "Hello " & Trim(wsEmail.Cells(lngEmlRow, intCustName)) & "," & vbLf & varBodyText.Value
                     End If
                     .attachments.DeleteAll
                     .attachments.Add (strSavePath & "\" & strCurFile)
                     .attachments.Add (strPDFPath)
                     .Display
                     'intResponse = MsgBox("Send message now and clear attachments?", vbOKOnly, "SEND MESSAGE")
                     'If intResponse = 1 Then
                     '   .Send
                     'End If
                 End With
                 On Error GoTo 0

I have tried:
Set OutMail = Nothing
Set OutApp = Nothing

The user would like to just hit the Send button instead of having the program send the email.

How do I clear the previous attachments?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
The macro will send out over one hundred emails but I need to clear the attachments between emails.
 
Upvote 0
My solution was to run this within its own subroutine. It works fine.

Now, can anyone tell me why it would work on my computer and not on a clients? She is not getting any errors and we both have Office 365 but it is not displaying the emails so she can send them.

Please, why is it sending from my computer and not hers?
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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