【问题标题】:Email based on checkbox - If function基于复选框的电子邮件 - 如果函数
【发布时间】:2019-03-20 14:59:51
【问题描述】:

我正在尝试根据是否选中复选框发送自动邮件。

代码在没有If 函数的情况下完美运行。但有了它,我得到:

错误 438:对象不支持此属性或方法。

我宁愿保留If 函数,这样邮件只能通过选中该框来发送。 如果没有If 功能,邮件也会在取消选中时发送。

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

【问题讨论】:

标签: excel vba checkbox outlook


【解决方案1】:

您可以尝试使用 ActiveSheet.OLEObjects ("CheckBox1")。 Object.Value> 0 作为检查它的条件。 欲了解更多信息,请参阅以下链接:

Using Control Names with the Shapes and OLEObjects Collections

Checking if a worksheet-based checkbox is checked

【讨论】:

    猜你喜欢
    • 2015-08-10
    • 2013-07-01
    • 2011-01-14
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 2016-03-06
    相关资源
    最近更新 更多