我正在尝试获取一个代码,用于保存特定Lotus Notes文件夹的附件并将其保存到本地文件夹(无需从Lotus Notes中删除电子邮件或附件)。但我继续收到错误消息:“对象或变量未设置” 我已经多次更改了代码但是我不知道我做错了什么。我是VBA的新手并且不了解所有代码。我非常感谢你的帮助。
谢谢!
Sub Save_Attachments()
Const stPath As String = "c:\Attachments"
Const EMBED_ATTACHMENT As Long = 1454
Const RICHTEXT As Long = 1
Dim noSession As Object
Dim noDatabase As Object
Dim noView As Object
Dim noDocument As Object
Dim noNextDocument As Object
Dim vaItem As Variant
Dim vaAttachment As Variant
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", " mail2\cbarrios.nsf")
Set noView = noDatabase.GetView("AAA")
Set noDocument = noView.GetFirstDocument
Do Until noDocument Is Nothing
Set noNextDocument = noView.GetNextDocument(noDocument)
If noDocument.HasEmbedded Then
Set vaItem = noDocument.GetFirstItem("Body")
If vaItem.Type = RICHTEXT Then
For Each vaAttachment In vaItem.EmbeddedObjects
If vaAttachment.Type = EMBED_ATTACHMENT Then
With vaAttachment
.ExtractFile stPath & vaAttachment.Name
End With
End If
Next vaAttachment
End If
End If
Set noDocument = noNextDocument
Loop
Set noNextDocument = Nothing
Set noDocument = Nothing
Set noView = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
End Sub
答案 0 :(得分:0)
给定的代码应该适用于Notes Richtextformat中的每个邮件。 它很可能会为每个mime消息抛出上述错误。
不幸的是,获取附件的方式因不同的格式而异。 但是:有一种适用于它们的通用解决方案。
Dim varAttachmentNamens as Variant
REM "Get the document here"
varAttachmentNames = noSession.Evaluate( "@AttachmentNames" , noDocument )
For Each strAttachmentName in varAttachmentNames
Set vaAttachment = noDocument.GetAttachment( strAttachmentName )
If vaAttachment.Type = EMBED_ATTACHMENT Then
Call vaAttachment.ExtractFile stPath & vaAttachment.Name
End With
End Forall