I'm trying to send an automated mail based on whether a checkbox is checked.
The code works perfectly without the If
function. But with it, I get:
Error 438: Object doesn't support this property or method.
I'd rather keep the If
function so the mail only gets sent by checking the box. Without the If
function, the mail gets sent when unchecking as well.
Sub Checkbox1_Click()
Dim OutLookApp As Object
Dim Mail As Object
Dim subject_ As String
Dim body_ As String
subject_ = "Something"
body_ = "Something else"
If Sheets("Sheet1").CheckBox1.Value = True Then
Set OutLookApp = CreateObject("Outlook.Application")
Set Mail = OutLookApp.CreateItem(0)
Application.DisplayAlerts = False
With Mail
.Subject = subject_
.Body = body_
.To = "email"
.CC = "otheremail"
.Importance = 2
.Send
End With
Application.DisplayAlerts = True
End If
End Sub
Aucun commentaire:
Enregistrer un commentaire