VBA-如何指定收件箱而不是使用收件箱



在我的excel电子表格中,我有A列和B列。A列中有电子邮件地址,B列中有唯一变量。下面的代码旨在查看收件箱,比较是否有任何主题行与B列中的唯一变量匹配,如果匹配,则将电子邮件转发到该唯一变量A列的电子邮件地址。这是当前的代码:

Public Sub Forward_Email(findSubjectLike As String, forwardToEmailAddresses As String)
Dim NSession As Object
Dim NMailDb As Object
Dim NViewObj As Object
Dim NInboxView As Object
Dim NDocument As Object
Dim NUIWorkspace As Object
Dim NUIDocument As Object
Dim NFwdUIDocument As Object


Set NSession = CreateObject("Lotus.NotesSession")
Call NSession.Initialize("password")

Set NUIWorkspace = CreateObject("Notes.NotesUIWorkspace")
Set NMailDb = NSession.GetDatabase("", "TEST.nsf")
Set NViewObj = NMailDb.GetView("Inbox")
Set NDocument = Find_Document(NInboxView, findSubjectLike)

If Not NDocument Is Nothing Then


Set NUIDocument = NUIWorkspace.EditDocument(False, NDocument)



NUIDocument.Forward



Set NFwdUIDocument = NUIWorkspace.CurrentDocument
Sleep 100


NFwdUIDocument.GoToField "To"
Sleep 100
NFwdUIDocument.InsertText forwardToEmailAddresses



NFwdUIDocument.GoToField "Body"
NFwdUIDocument.InsertText "This email was forwarded at " & Now
NFwdUIDocument.InsertText vbLf


NFwdUIDocument.Send
NFwdUIDocument.Close

Do
Set NUIDocument = NUIWorkspace.CurrentDocument
Sleep 100
DoEvents
Loop While NUIDocument Is Nothing
NUIDocument.Close

Else

MsgBox vbCrLf & findSubjectLike & vbCrLf & "not found in Inbox"
End If

Set NUIDocument = Nothing
Set NFwdUIDocument = Nothing
Set NDocument = Nothing
Set NMailDb = Nothing
Set NUIWorkspace = Nothing
Set NSession = Nothing

End Sub
Private Function Find_Document(NView As Object, findSubjectLike As String) As Object
Dim NThisDoc As Object
Dim thisSubject As String

Set Find_Document = Nothing

Set NThisDoc = NView.GetFirstDocument
While Not NThisDoc Is Nothing And Find_Document Is Nothing
thisSubject = NThisDoc.GetItemValue("Subject")(0)
If LCase(thisSubject) = LCase(findSubjectLike) Then Set Find_Document = NThisDoc
Set NThisDoc = NView.GetNextDocument(NThisDoc)
Wend
End Function

问题是,现在代码在登录用户(在本例中是我)的用户收件箱中查找。我打开了另一个收件箱(让我们称之为TEST)。我是否可以指定此代码来查看打开的TEST收件箱中的信息。现在它将来自我收件箱的信息与TEST进行比较,因为它触发了错误行";在收件箱中找不到";。

它目前所做的是在我的发现中寻找唯一的变量,然后尝试与主题行的TEST进行比较以转发它。我希望它既在TEST中查找,又与TEST进行对比。

您声明"问题是,现在代码在登录使用"的用户收件箱中查找;。事实并非如此。它使用NSession。CurrentDatabase、和NotesSession使用Notes OLE类加载到VBA中。这是OLE类,因为您使用的是Notes。NotesSession而不是Lotus。注意选择。在COM类中,如果您使用Lotus,则会加载这些类。备注会话。,CurrentDatabase属性未定义。在OLE类中,我真的不知道OLE类中的预期行为是什么,但我确信,不能总是依赖当前数据库作为当前用户的邮箱数据库。

在任何情况下,如果要访问其他用户的收件箱,首先必须打开该用户的邮箱数据库。要做到这一点,您必须知道邮箱数据库在哪个服务器上,以及邮箱的路径在该服务器上。您可以通过编写代码来读取Domino目录中该用户的Person文档中的信息,也可以将该信息放入每个用户的电子表格中。这样,您就可以使用NotesSession。GetDatabase,打开数据库,并以访问自己的邮箱数据库的方式访问它。

相关内容

最新更新