【问题标题】:Object or with variable not set - save attachments from Lotus notes未设置对象或变量 - 保存 Lotus notes 中的附件
【发布时间】:2015-09-11 13:13:53
【问题描述】:

我正在尝试获取一个代码,用于保存特定 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

【问题讨论】:

  • 这个错误出现在哪一行?它应该以黄色突出显示。

标签: vba object lotus


【解决方案1】:

给定的代码应该适用于 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

查看this stackexchange postthis link at IBM 了解更多详情。

【讨论】:

  • 感谢 Torsten 的回答。我已经检查了您发送给我的链接,但是(正如我提到的我是新手)我仍然无法使用它。我收到一条错误消息:编译时出错(我希望这是正确的翻译)。它向我显示了错误:Forall strAttachmentName in varAttachmentNames 我也不确定我是否将您的代码放在正确的位置(在我的内部)。
  • 对不起,我刚刚复制了 lotusscript 代码。大多数情况下,它在 VBA 中的工作方式相同。它必须是For Each,而不是Forall。我在上面的例子中解决了这个问题。
猜你喜欢
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多