通过 VBA 读取 Lotus Notes 文档中的字段

Read fields in Lotus Notes Documents Through VBA

我正在尝试编写 VBA 代码来从 Lotus Notes 文档的字段中读取数据。目前,我可以使用 FieldGetText 方法读取数据,但这仅在我打开文档时有效。我需要能够在不打开文档的情况下循环浏览文档,因为文档有数百个。我需要能够从许多文档中读取这些相同的字段,但不知道如何遍历它们。我的代码目前是:

    Set LotusNotes = CreateObject("Notes.NotesUiWorkspace")
    Set CurrentDoc = LotusNotes.CurrentDocument
    While Not (CurrentDoc Is Nothing)

    ' Affectation of data
    DueDate = CurrentDoc.FieldGetText("RevDueDate")
    DueTime = CurrentDoc.FieldGetText("RevDueTime")
    DateClosed = CurrentDoc.FieldGetText("DateClosed")

    Wend

我知道这使用了前端对象。我能够使用可以循环遍历文档(无需打开文档)的后端对象,但是数据(特别是日期)与文档中的字段文本不匹配。该代码如下所示:

Set LotusNotes = CreateObject("Notes.NotesSession")
Set db = LotusNotes.GetDatabase("")
Set view = db.GetView(view_name)
view.AutoUpdate = False
Set columnview = view.AllEntries

Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
    revDate = doc.GetItemValueDateTimeArray("RevDueDate")
    revDate = doc.RevDueDate 
Set doc = view.GetNextDocument(doc)
Wend

基本上,我只是想知道是否可以使用我首先尝试的 NotesUIWorkspace class 循环遍历多个文件,或者是否可以以某种方式使用 FieldGetText NotesWorkspace class 代替。

感谢任何帮助,谢谢。

有可能,而且最好使用 'Back end' 对象 Notes.NotesSession。所以试试这个:

Set doc = view.GetFirstDocument
While Not (doc Is Nothing)
    'Check if you have the field in the document
    if doc.HasItem("RevDueDate") Then
        revDate = doc.getFirstItem("RevDueDate").Text
    End If
Set doc = view.GetNextDocument(doc)
Wend

也可以通过在客户端打开每个文档、获取字段数据并关闭文档来使用 Notes.NotesUiWorkspaceobject,但我强烈建议 不要 这样做是因为如果您需要循环处理更多文档,很可能会使 Notes 客户端崩溃。

您正在使用植根于 Notes.NotesUIWorkspace 的 "front-end" class 注释。这些是 OLE classes,这意味着它们需要 Notes 客户端 运行 并且它们在打开的文档上工作。还有根植于 Notes.NotesSession 的后端 classes。这些也是 OLE classes,因此它们仍然需要 Notes 客户端为 运行,但它们可以访问其他文档(以及其他数据库、服务器等)。还有一组根植于 Lotus.NotesSession 的后端 classes。注意不同的前缀。这些是 COM classes,所以他们不需要 Notes 客户端是 运行 - 虽然它确实必须安装和配置,并且您的代码将必须提供用户密码,因为客户端赢了'提示它。

您可以找到 NotesSession classhere. Down near the bottom of the page, you'll find links to information about using them via OLE or COM. You can find a bunch of examples based on using the COM classes here 的文档和示例,包括遍历数据库视图中的文档的文档和示例。除了会话的初始设置外,如果您使用 OLE,它将是相同的。