vba - 使用 Excel VBA 脚本遍历 Lotus Notes 中的所有视图
问题描述
我有一个脚本(在网上找到并根据我的需要进行了调整),它可以访问 Lotus Notes 的特定视图,从每封电子邮件中获取一些信息并将任何附件保存到给定文件夹中。如果我想为更多视图执行此操作,我目前在我的工作表中有这些视图的名称并循环它们。我想做的是遍历所有视图并做同样的事情。
我不是专业的开发人员,也不完全熟悉使用对象。然而,这个问题对我来说太复杂了。Lotus Notes 对象也不是最容易理解的。
我正在使用以下代码,这当然是更大(工作)脚本的一部分。对于初学者来说,只需能够遍历所有视图并打印视图的名称就足够了。从那以后,我想我可以自己做剩下的事情。任何人都可以调整代码以使其工作。
Public Sub Get_Notes_Email_Text()
Dim NSession As Object 'NotesSession
Dim NMailDB As Object 'NotesDatabase
Dim NDocs As Object 'NotesDocumentCollection
Dim NDoc As Object 'NotesDocument
Dim NNextDoc As Object 'NotesDocument
Dim view As String
'Start a Lotus Notes session
Set NSession = CreateObject("Notes.NotesSession")
'Connect to the Lotus Notes database
Set NMailDB = NSession.GetDatabase("", "C:\Users\" & Environ("Username") & "\AppData\Local\IBM\Notes\Data\mail\" & Environ("Username") & ".nsf") 'Default server en database
If Not NMailDB.IsOpen Then
NMailDB.OpenMail
End If
'Loop through all views and print .Name tot Immediate Window
' Dim Map As Variant
' Dim Mappen As Object
' Set Mappen = NMailDB.Views
'
' For Each Map In Mappen
' Debug.Print Map.Name
' Next Map
'
End Sub
解决方案
比浏览所有视图更容易的是只转到一个显示所有文档的视图。如果是邮件数据库,则视图称为“($All)”
Set allDocsView = NMailDB.getView("($All)")
allDocsView.autoUpdate = false
然后,您可以使用遍历视图中的文档
Set docToProcess = allDocsView.GetFirstDocument
While Not ( docToProcess Is Nothing )
'Do what you plan to do here
Set docToProcess = allDocsView.GetNextDocument( docToProcess )
Wend
更新:当您想遍历文件夹而不是视图时,您需要执行以下操作
Dim sess As New notessession
Dim db As NotesDatabase
Dim views As Variant
Set db = sess.CurrentDatabase
views = db.Views
Forall v In views
If v.isFolder Then ' Needed so that we are only processing Folder objects and not views - you will need to check that you are not processing system folders e.g. $Inbox etc
'Do your processing of documents here
End If
End Forall
推荐阅读
- sql-server - SQL Server:插入后更新同一个表
- excel - 如何在 MS Excel 中跨列按字母顺序对行进行排序?
- html - 如何在 Laravel 5.7 中制作与提交按钮功能相同的图标链接?
- python - 我可以在不使用 Sprites 的情况下使用 .colliderect() 吗?-Py游戏
- java - 如何使用移动加速度计计算虚拟球的高度
- sql - 由于字段的时间戳超出标准 SQL 时间戳的范围,无法在 Google BigQuery 中删除或更新行
- java - 严重:异常启动过滤器 ShiroFilter 错误
- android - VFY:register1 v4 type 2,通缉 17
- c - 这是 Vernam Cipher 的 C 代码,如何将数字作为输入消息而不是字符串?
- c++ - 如何在类派生层次结构的所有步骤中调用方法?