我有一個從蓮花筆記下載附件的代碼。問題是每次運行它下載所有的附件。我怎樣才能讓條件不下載以前下載的附件?如何使用vb腳本從蓮花筆記下載附件
Option Explicit
Sub Save_Attachments_Remove_Emails()
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 noRemoveDocument As Object
Dim noNextDocument As Object
'Embedded objects are of the datatype Variant.
Dim vaItem As Variant
Dim vaAttachment As Variant
'Instantiate the Notes session.
Set noSession = CreateObject("Notes.NotesSession")
'Instantiate the actual Notes database.
'(Here is the personal e-mail database used and since it's a
'local database no reference is made to any server.)
Set noDatabase = noSession.GETDATABASE("CAT-DH-23.apd.cat.com/Servers/Caterpillar", "mail\pamsmine.nsf")
' Please use this Open Function if the server is not referenced and GETDATABASE
' opens the db file if the file is in local system.
'Call noDatabase.Open("", "C:\notes\test.nsf")
'Folders are views in Lotus Notes and in this example the Inbox
'is used.
Set noView = noDatabase.GetView("($Inbox)")
'Get the first document in the defined view.
Set noDocument = noView.GetFirstDocument
'Iterate through all the e-mails in the view Inbox.
Do Until noDocument Is Nothing
Set noNextDocument = noView.GetNextDocument(noDocument)
'Check if the document has an attachment or not.
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
'Save the attached file into the new folder.
vaAttachment.ExtractFile stPath & vaAttachment.Name
'Set the e-mail object which will be deleted.
Set noRemoveDocument = noDocument
End If
Next vaAttachment
End If
End If
Set noDocument = noNextDocument
'Delete the e-mails which have an attached file.
' If Not noRemoveDocument Is Nothing Then
' noRemoveDocument.Remove (True)
' Set noRemoveDocument = Nothing
'End If
Loop
'Release objects from memory.
Set noRemoveDocument = Nothing
Set noNextDocument = Nothing
Set noDocument = Nothing
Set noView = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
MsgBox "All the attachments in the Inbox have successfully been saved" & vbCrLf & _
"and the associated e-mails have successfully been deleted.", vbInformation
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
你如何知道如果附件已經下載呢? Notes郵件數據庫中沒有標誌來指定是否下載附加文檔。一種方法是測試文件是否已經存在,但是這會給不同電子郵件附加的具有相同名稱的不同文件帶來錯誤。另一種方法是爲每個包含附件的電子郵件創建一個文件夾。 –
我們不能將處理的郵件標記爲已讀。然後只有未讀郵件將被處理。這只是一個想法。請建議,如果這是可能的?還建議我們如何全天候運行這個腳本。 – user3859736
還有一點@CST-Link,將不會有相同名稱的文件。現在請建議我如何實現這一目標? – user3859736