0

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
4

1 Answer 1

0

You can try using the ActiveSheet.OLEObjects ("CheckBox1"). Object.Value> 0 as condition to check it. For more information, please see the following links:

Using Control Names with the Shapes and OLEObjects Collections

Checking if a worksheet-based checkbox is checked

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.