【发布时间】:2017-05-08 07:24:36
【问题描述】:
我有一个包含收件人、抄送和密送列的电子邮件列表。当复选框为 TRUE 时,它会将电子邮件添加到 Outlook 中的特定行。
我想做的是在运行宏时将时间戳应用于单元格,仅用于“J”列中的 TRUE 复选框。
这就是我正在使用的。
Sub SendEmail()
' Set up outlook objects for emailing
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
' Body text for the email
Dim strbody As String
strbody = ""
' Strings to contain the email addresses
Dim sendTo As String
sendTo = ""
Dim sendCC As String
sendCC = ""
Dim sendBCC As String
sendBCC = ""
' The cell containing the email address (loop variable)
Dim emailCell As Range
With ActiveSheet
' Cycle through email addresses, from B3 to one before next blank cell in column
For Each emailCell In .Range("B3", .Range("B3").End(xlDown))
' Check each TRUE/FALSE column in same row, add email addresses accordingly
If .Cells(emailCell.Row, "E").Text = "TRUE" Then
sendTo = sendTo & "; " & emailCell.Text
End If
If .Cells(emailCell.Row, "G").Text = "TRUE" Then
sendCC = sendCC & "; " & emailCell.Text
End If
If .Cells(emailCell.Row, "I").Text = "TRUE" Then
sendBCC = sendBCC & "; " & emailCell.Text
End If
Next emailCell
End With
' Generate email in outlook objects defined above
On Error Resume Next
With OutMail
.To = sendTo
.CC = sendCC
.BCC = sendBCC
.Subject = ""
.HTMLBody = strbody
.Display
' If you don't want to display the email before sending it,
' simply use .Send instead of .Display
End With
On Error GoTo 0
End Sub
【问题讨论】:
-
您谈论的是复选框,但您的代码涉及单元格中的 TRUE 值。是否有复选框。如果不是,并且单元格正在触发动作,如果三个单元格中只有一个为真,是否会触发?时间戳应该有多详细:天?第二?还有什么?
-
我只是将其更改为一个侧翼代码,当单元格被触摸时,它会在两个侧翼字符之间切换,看起来像一个未选中的框和一个选中的框。现在可以检查任何人,它将在该位置添加该电子邮件。这样您就可以将其发送给自己以及自己抄送和密送。我正在寻找宏运行的当前日期和时间。谢谢
-
如果您“查找当前运行宏的日期和时间”,那么它与您所谓的“复选框”的值无关。只需选择一个单元格并输入类似 =now() 的内容,
pastevalue那个单元格。 -
@EEM,OP 希望在运行时添加时间戳。您的解决方案似乎很好,但是您关于 OP 不应使用复选框来确定是否为该行添加时间戳的声明对我来说似乎是错误的。
-
@DougGlancy,OP 说只是想知道宏何时运行,这意味着无论结果如何,所以不需要检查其他任何东西......