vba 莲花笔记到VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14882444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
lotus notes to VBA
提问by hitek
I'm stuck with this problem for days
我被这个问题困扰了好几天
I have to read a specific mailbox in lotus notes and bring all the content into an excel spread sheet
我必须阅读莲花笔记中的特定邮箱并将所有内容放入excel电子表格中
but so far I have only been able to read the default inbox and have no way of switching to the other mailbox. I 'm really new to VBA can any one help me sort this out
但到目前为止我只能读取默认收件箱,无法切换到其他邮箱。我对 VBA 真的很陌生,谁能帮我解决这个问题
here is the code I 'm using
这是我正在使用的代码
Set NSession = CreateObject("Notes.NotesSession")
'get the name of the mailfile of the current user
DbLocation = NSession.GETENVIRONMENTSTRING("mail/mailbox", True)
'Get the notesdatabase for the mail.
Set NMailDb = NSession.GETDATABASE("mailboxer", DbLocation)
MsgBox (DbLocation)
I get an empty msgbox poping up
我弹出一个空的 msgbox
回答by Richard Schwartz
GetEnvironmentString() reads the notes.ini file. I'm not sure that's what you really want to be doing. Just from the syntax, I think you're using "mail/mailbox" as a placeholder for the actual path to the mailbox that you're looking for. E.g., you're really trying to read the mail from something like "mail/jsmith.nsf". (If I'm wrong, and you really do want to be reading the notes.ini file to get the location of the mail file, then your problem is that "mail/mailbox" is not a valid key for an ini file entry.)
GetEnvironmentString() 读取 notes.ini 文件。我不确定那是你真正想做的事情。仅从语法来看,我认为您正在使用“邮件/邮箱”作为您要查找的邮箱实际路径的占位符。例如,您实际上是在尝试从“mail/jsmith.nsf”之类的内容中读取邮件。(如果我错了,并且您确实想阅读 notes.ini 文件以获取邮件文件的位置,那么您的问题是“邮件/邮箱”不是 ini 文件条目的有效键。 )
My next assumption is that the Domino server where the mailbox lives is called "mailboxer", because that's what you're putting in the first argument of GetDatabase().
我的下一个假设是邮箱所在的 Domino 服务器被称为“mailboxer”,因为这是您在 GetDatabase() 的第一个参数中放入的内容。
If I'm right about these things, then what what you need is
如果我对这些事情是正确的,那么你需要的是
Set NMailDb = NSession.GETDATABASE("mailboxer", "mail/mailbox")
where "mail/mailbox" is replaced with the actual path to the mailbox that you are trying to open.
其中“邮件/邮箱”被替换为您尝试打开的邮箱的实际路径。
回答by D.Bugger
Some thoughts:
一些想法:
- use Lotus.NotesSession if you don't have to interact with the Notes UI (Lotus.NotesSession is COM based, whereas Notes.NotesSession is OLE based)
- make sure the user of the Notes client on the workstation running your VBA application has the rights require to open and read the mailbox
- 如果您不必与 Notes UI 交互,请使用 Lotus.NotesSession(Lotus.NotesSession 是基于 COM 的,而 Notes.NotesSession 是基于 OLE)
- 确保运行 VBA 应用程序的工作站上的 Notes 客户端用户具有打开和读取邮箱所需的权限
回答by Ed Schembor
As D. Bugger stated, you need to be sure you have the Notes client installed on the same client machine your VB code will run, and you need to be sure the folder with the nnotes.exe file and the folder with the notes.ini file are in your environment path. (If not, you will get a COM error instantiating the Notes.NotesSession object.
正如 D. Bugger 所说,您需要确保在运行 VB 代码的同一台客户端机器上安装了 Notes 客户端,并且需要确保包含 nnotes.exe 文件的文件夹和包含 notes.ini 的文件夹文件位于您的环境路径中。(如果没有,您将在实例化 Notes.NotesSession 对象时遇到 COM 错误。
If this helps, here is some starter code - not tested, but a rough guide... This walks through all documents in a Notes mailbox database, ignores anything except email documents (which have the form field = "Memo") and grabs some fields from each email.
如果这有帮助,这里有一些入门代码 - 没有经过测试,而是一个粗略的指南......这将遍历 Notes 邮箱数据库中的所有文档,忽略除电子邮件文档(具有表单字段 = "Memo")之外的任何内容并抓取一些每封电子邮件中的字段。
Public Sub exportNotesMail(MailServer$, MailDBPath$)
Dim mailDb As Object, doc As Object, alldocs As Object, Session As Object
Set Session = CreateObject("Notes.NotesSession")
Set mailDb = Session.GETDATABASE(MailServer, MailDbPath$)
If mailDb.IsOpen = False Then mailDb.OPENMAIL
Set alldocs = mailDb.AllDocuments
Set doc = alldocs.GetFirstDocument
while not (doc is nothing)
If doc.GetItemValue("Form")(0) = "Memo" Then
thisSubject = doc.getItemValue("Subject")(0)
thisFrom = doc.getItemValue("From")(0)
' get more field values
' Export to Excel or wherever
End If
Set doc = alldocs.GetNextDocument(doc)
Next i
' done
End Sub
call exportNotesMail ("MyServer", "mail\myMailFile.nsf")