我编写了一个脚本,它生成一个 Lotus Notes 电子邮件以在特定时间间隔发布数据。这个脚本是 Macro2 - Macro5。宏 2 - 宏 5 都是相同的,但我在不同的子目录下复制了脚本以尝试诊断我的问题。我遇到的问题有时是例如晚上 8 点,会生成 4 封电子邮件。一封电子邮件将由宏 5 正确触发,但在晚上 8 点发送的其他电子邮件已由宏 2 触发。我知道这一点是因为我在每个宏中添加了一个额外的行,以在电子邮件中指明是哪个宏生成了它。
我正在使用以下内容来调用这些潜艇:
在“这本工作簿”中,我有:
Private Sub Workbook_Open()
Call DailyAM
Call DailyPM
End Sub
在模块 1 中:
Sub DailyAM()
Application.OnTime TimeValue("06:00:00"), "Macro2"
Application.OnTime TimeValue("10:00:00"), "DailyAM"
End Sub
Sub DailyPM()
Application.OnTime TimeValue("12:01:00"), "Macro3"
Application.OnTime TimeValue("16:00:00"), "Macro4"
Application.OnTime TimeValue("20:00:00"), "Macro5"
Application.OnTime TimeValue("23:59:00"), "DailyPM"
End Sub
真的很困惑为什么会这样。可以肯定这个问题与宏 2-5 无关,但这里只是以防万一:
Sub Macro5()
Windows("Silo report test v2.xlsm").Activate
Application.Calculate
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
Set Session = CreateObject("Notes.NotesSession")
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
Set MailDoc = Maildb.CreateDocument
MailDoc.Form = "Memo"
'Email address array changed for privacy
vaRecipient = VBA.Array("example@example.com")
MailDoc.SendTo = vaRecipient
MailDoc.Subject = Range("B1").Value
Set workspace = CreateObject("Notes.NotesUIWorkspace")
Dim notesUIDoc As Object
Set notesUIDoc = workspace.EditDocument(True, MailDoc)
Call notesUIDoc.GOTOFIELD("Body")
Call notesUIDoc.FieldClear("Body")
Call notesUIDoc.FieldAppendText("Body", Range("B9").Value & vbCrLf & vbCrLf & Range("b10").Value & Range("I10").Value & Range("D10").Value & vbCrLf & Range("b11").Value & Range("I11").Value & Range("D11").Value & vbCrLf & Range("b12").Value & Range("I12").Value & Range("D12").Value & vbCrLf & vbCrLf & Range("b13").Value & Range("I13").Value & Range("D13").Value & vbCrLf & vbCrLf & Range("b14").Value & Range("C14").Value & Range("D14").Value & vbCrLf & vbCrLf & Range("b15").Value & Range("I15").Value & Range("D15").Value & vbCrLf & Range("F4").Value & vbCrLf)
notesUIDoc.Send
notesUIDoc.Close
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub