Hello I am trying to make a button that allows my coworkers to save as in a specific folder and email their excel forms from excel but I've run into the problem where the attachment doesn't attach. This is the code I am using, what am I doing wrong?
Dim FileName As String
Dim Path As String
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Path = "I:\AAA-PURCHASE ORDERS\2019 PO's" & ""
FileName = "PO#_" & Range("H4") & "_" & Range("C10") & Format(Now(), "mm-dd-yyyy") & ".xlsm"
Application.EnableEvents = False
ThisWorkbook.SaveAs FileName:=Path & FileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ErrorHandler:
Application.EnableEvents = True
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.to = ""
.CC = ""
.BCC = ""
.Subject = ""
.Body = ""
.Display
.Attachment.Add Path & FileName
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Dim FileName As String
Dim Path As String
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Path = "I:\AAA-PURCHASE ORDERS\2019 PO's" & ""
FileName = "PO#_" & Range("H4") & "_" & Range("C10") & Format(Now(), "mm-dd-yyyy") & ".xlsm"
Application.EnableEvents = False
ThisWorkbook.SaveAs FileName:=Path & FileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
ErrorHandler:
Application.EnableEvents = True
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.to = ""
.CC = ""
.BCC = ""
.Subject = ""
.Body = ""
.Display
.Attachment.Add Path & FileName
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub