–1 vote
in VBA by Beginner (1 point)
Sub Email()

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Variant
    Dim sht As Worksheet
    Dim CashierName As String
    Dim CashierTill As String
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim Att As String
    
    CashierName = Range("j4")
    CashierTill = Range("f4")
    
    TempFilePath = Environ$("temp") & "\"
    TempFileName = ActiveWorkbook.Name
 Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs TempFilePath & TempFileName
     ActiveWorkbook.SaveAs TempFilePath & "tempGolfCourseTill.xlsm"
    Att = TempFilePath & TempFileName
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "XXXXX@gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "CXXXX!"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Update
    End With
    With iMsg
        Set .Configuration = iConf
        .To = "XXXX@rexburg.org" 'sendToEmail
        .CC = ""
        .BCC = ""
        .From = "XXXX@gmail.com"
        .ReplyTo = "XXXX@rexburg.org"
        .Subject = "Rexburg Golf Till " & CashierTill & " " & Now
        .TextBody = "This is the Till balance per " & CashierName & "."
        .Attachments.Add Att
        
        .Send
    End With
     Application.ScreenUpdating = True
  Application.EnableEvents = True
  Application.DisplayAlerts = True
End Sub

 

by Beginner (56 points)
+1
what is happening?

error? wrong attachment? no attachment? no email sent? email sent but not received by recipient? which file are your trying to attach? is the saveAs tempfilename being saved? is that the path of the original active document?

Please log in or register to answer this question.

Welcome to wellsr Q&A
Ask any questions you have about VBA and Python and our community will help answer them. wellsr Q&A is the standalone question and answer platform for wellsr.com. If you have a question about one of our specific tutorials, please include a link back to the tutorial.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Looking for something else? Hire our team directly through ourVBA Help page, instead.

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...