两个动作触发一个标准 - 但只有一个触发,不知何故

时间:2015-08-11 19:19:17

标签: excel vba

我有一些代码可以发送一些东西的电子邮件摘要。在某些情况下,主题行中会添加一个额外的注释,另一方是CC' d。

这就是问题所在 - 昨天我们有四个案例触发了额外的音符,但其中只有三个案例包括CC。无论出于何种原因,有一次,代码将消息添加到主题,但不包括CC,即使两个事件都在同一指标上触发,并且它肯定在大多数时间都有效。

我已经审核了代码,但我不能为我的生活确定如何发生这种情况...... 这只是Excel的一个例子吗?

Public Sub EmailResults()
  Dim rng As Range
  Dim i As Integer
  Dim id, thisDt, Boom As String
  Dim olApp As Outlook.Application
  Dim OLmail As Outlook.MailItem

  Set rng = Nothing
  id = [id].Value
  thisDt = [thisDt].Value
  If [Boom_Ind] Then Boom = " **NOTICE ME**" Else Boom = ""

  With Application
      .EnableEvents = False
      .ScreenUpdating = False
  End With

  Set olApp = CreateObject("Outlook.Application")
  Set OLmail = olApp.CreateItem(olMailItem)

  With OLmail
      .Subject = "Coolness: " & id & " - Date: " & thisDt & Boom
      .HTMLBody = RangetoHTML(rng)
      .To = "coolness@cool.com"
      If [Boom_Ind] Then
        .CC = "awesome@cool.com"
      End If
      .BCC = ""
  End With

  If [AutoEmail] Then OLmail.Send 'Else OLmail.Display

  With Application
      .EnableEvents = True
      .ScreenUpdating = True
  End With

  Set OLmail = Nothing
  Set olApp = Nothing
  Exit Sub

0 个答案:

没有答案