Send Email not running

Eclektics

New Member
Joined
Jun 9, 2015
Messages
24
Hi everyone,

I'm at a bit of a loss with this one as the code I'm using I've used before without issue. My goal is to have Excel move a worksheet to a new workbook, save that file and send it and then kill the file. All the code is working apart from the code to send an email, when I've took out of this code from my main module and ran it independently and nothing happens. Any help will be massively appreciated.

Code:
 Sub System_Issue_Mail()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String


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


    strbody = "Hi" & vbNewLine & vbNewLine & _
              "Please find attached a new archived certificate request." & vbNewLine & _
              "Thanks"


    On Error Resume Next
    With OutMail
        .To = "System.support@.org.uk"
        .CC = ""
        .BCC = ""
        .Subject = "A New System Issue has been raised by user" & usr
        .Body = ""
        .Attachments.Add ("C:\Users\" & usr & "\Documents\TEMPFILETBR.xlsx")
        .Display   '.Send
    End With
    On Error GoTo 0


    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi

I suggest to check first that file exist, if exists, attached, if not, sent without attachment.


Code:
 Sub System_Issue_Mail()


    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
[U][B]    Dim AttFile As String[/B][/U]
[U][B]    AttFile = "C:\Users\" & usr & "\Documents\TEMPFILETBR.xlsx"[/B][/U]


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




    strbody = "Hi" & vbNewLine & vbNewLine & _
              "Please find attached a new archived certificate request." & vbNewLine & _
              "Thanks"




    On Error Resume Next
    With OutMail
        .To = "System.support@.org.uk"
        .CC = ""
        .BCC = ""
        .Subject = "A New System Issue has been raised by user" & usr
        .Body = ""
[U][B]        If Len(Dir(AttFile)) <> 0 Then[/B][/U]
[U][B]            .Attachments.Add AttFile[/B][/U]
[U][B]        End If[/B][/U]
        .Display   '.Send
    End With
    On Error GoTo 0




    Set OutMail = Nothing
    Set OutApp = Nothing
    
End Sub
 
Upvote 0
Thanks KOKOSEK, the code is working when sending an email now. The issue only happens when I ask excel to display the email rather than send, rather than showing the email it does nothing.
 
Upvote 0
Try commenting out the On Error Resume Next so that you can see what's actually happening.
 
Upvote 0
Thanks KOKOSEK, the code is working when sending an email now. The issue only happens when I ask excel to display the email rather than send, rather than showing the email it does nothing.

As you see in my code I've displayed email and i don't have any problems.
If file exists is attached, if file does not exists, email is shown without attachment.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,803
Members
449,048
Latest member
greyangel23

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