【发布时间】: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
【问题讨论】:
-
你在哪一行得到错误?
-
那么 Sheets("Sheet1") 不包含属性
CheckBox1。你一定要看看stackoverflow.com/questions/11741836/… -
检查此答案以及复选框条件stackoverflow.com/questions/11991308/…
标签: excel vba checkbox outlook