Can't get to any info from Lotus Notes using VBA

时间:2017-06-12 16:58:55

标签: excel-vba lotus-notes vba excel

Thanks in advance for any help!

I'm ultimately trying to pull information from specific emails based on subject line. Working up to the problem the below code was a test to pull up a subject line. However it runs through 132 documents without a single subject identified as anything other than blank. Using this same Initialize and GetDatabase method I successfully sent emails through Lotus Notes, so I don't think I'm after the wrong docs somehow. Below code written in VBA through Excel have Lotus Notes 8.5

Anyone see a reason why I would get nothing but blanks going through all of the docs in the Notes Database?

Sub LotusGetView()

Dim Nsess As New NotesSession
Dim Ndb As NotesDatabase
Dim Ndocs As NotesDocumentCollection
Dim Ndoc As NotesDocument, docNext As NotesDocument
Dim c As Long
Dim memSubj As Variant


Nsess.Initialize
Set Ndb = Nsess.GetDatabase("", "names.nsf")

Set Ndocs = Ndb.AllDocuments

c = 1

Set Ndoc = Ndocs.GetFirstDocument
Do Until Ndoc Is Nothing Or c = 1000
    Set docNext = Ndocs.GetNextDocument(Ndoc)

    memSubj = Ndoc.GetItemValue("Subject")(0)

    If memSubj <> "" Then

        MsgBox memSubj

    End If


    Call Ndoc.Remove(True)

    Set Ndoc = docNext

    c = c + 1
Loop

MsgBox c

End Sub

1 个答案:

答案 0 :(得分:1)

你的问题就在这一行:

Set Ndb = Nsess.GetDatabase("", "names.nsf")

您正在打开names.nsf。这是用户的个人通讯录数据库。它不是用户的邮件数据库。您之前发送邮件的工作是有效的,因为您不需要访问邮件数据库来发送邮件。您可以从任何地方发送邮件。要读取邮件,您必须打开邮件数据库。

OpenMailDatabase类的NotesDbDirectory方法为您提供了一种查找和打开当前用户的邮件数据库的简便方法。