I found some code that works. But I have one small issue.
Right now the macro is looking at all the files in my inbox. I want to change this to a folder i have setup as "test". I replaced the word "$Inbox" with "$test" but it didn't work. Gave me the error "Run-time error '91' Object variable or With block variable not set" and highlighted the line containing Set noDocument = noView.GetFirstDocument
Any ideas?
Here is my code:
Option Explicit
Const stPath As String = "c:\Attachments\"
Const EMBED_ATTACHMENT As Long = 1454
Const RICHTEXT As Long = 1
Sub Save_Remove_Attachments()
Dim noSession As Object
Dim noDatabase As Object
Dim noView As Object
Dim noDocument 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("", "")
If Not noDatabase.IsOpen = True Then noDatabase.Openmail 'open the mail part of it
'Folders are views in Lotus Notes and in this example the Inbox is used.
Set noView = noDatabase.GetView("($test)")
'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
'Although the following approach is not necessary for this
'kind of operations it may be a good approach to use in general.
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 and remove it from the e-mail.
With vaAttachment
.ExtractFile stPath & vaAttachment.Name
' .Remove
End With
'Save the e-mail in order to reflect the deleting of the attached file.
'(A more sophisticated approach may be considered if several e-mails have
'several attachments in order to avoid a repeately saving of one e-mail.)
noDocument.Save True, False
End If
Next vaAttachment
End If
End If
Set noDocument = noNextDocument
Loop
'Release objects from memory.
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 and removed." _
, vbInformation
End Sub