I have code (see below) to send an email automatically if a button is pressed at it has been 30 days since the last time is was pressed. I am trying to attach the spreadsheet to the email but I am having no luck.
This is the code I'm using:
Private Sub CommandButton1_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
x = Date
If x - Cells(3, 4) > 30 Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "A relief valve needs to be tested. Please look at the attached spreadsheet to see which pressure relief it is."
On Error Resume Next
With OutMail
.To = email@email.com
.CC = ""
.BCC = ""
.Subject = "Pressure Relief Valve"
.Body = strbody
.Send 'Sends Email"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Cells(3, 4) = x
End If
End Sub
I've tried using .Attachments.Add but no luck
This is the code I'm using:
Private Sub CommandButton1_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
x = Date
If x - Cells(3, 4) > 30 Then
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "A relief valve needs to be tested. Please look at the attached spreadsheet to see which pressure relief it is."
On Error Resume Next
With OutMail
.To = email@email.com
.CC = ""
.BCC = ""
.Subject = "Pressure Relief Valve"
.Body = strbody
.Send 'Sends Email"
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Cells(3, 4) = x
End If
End Sub
I've tried using .Attachments.Add but no luck