Site hosted by Angelfire.com: Build your free website today!

Say OLE!, to COM with Lotus Notes

Save Attachments

How to save attachments with Lotus Notes.
This is a complementary code that we can use with previous(Say OLE!, to COM...) example.

Lotus Notes

Different version of Notes exposes objects in different way.
Version 4.x exposes throghout OLE, Version 5.x throghout really COM.
You could say: What is the difference?
The most important one, at least to me, is that if you want to work with objects, version 4.x supports Late Binding, which is awful enought to got your hair green. Besides, you cannot access Autolist members from VB IDE since you need to declare objects variables to manage Notes objects with a generic "as Object".
Well, to access objects from Notes version 4.x, you need to set a reference to Lotus Notes Automation Classes, with version 5.x you need to set a reference to Lotus Domino Objects.
The following code shows how to detach files that cames on mails from Inbox folder. It is done with Version 5.x.
To do it with version 4.x, just replace those strong typed variables with the infamous "as Object" stuff and un-comment Const declaration lines.

This sub assumes that you already has been logged in to mail server and opened database.
Public Sub NotesSaveAttachs(sPathToSave As String)
Dim View As New Domino.NotesView
Dim nDoc As Domino.NotesDocument
'Dim nDoc2Remove As Domino.NotesDocument
'const RICHTEXT = 1
'const EMBED_ATTACHMENT = 1454
Set View = oDB.GetView("($Inbox)")

Set nDoc = View.GetFirstDocument
Dim itm As Variant
While Not (nDoc Is Nothing)
    If nDoc.HasEmbedded Then
        Set itm = nDoc.GetFirstItem("Body")
        If itm.Type = RICHTEXT Then
            Dim attch As Variant
            For Each attch In itm.EmbeddedObjects
                If (attch.Type = EMBED_ATTACHMENT) Then
                    attch.ExtractFile sPathToSave & attch.Name
                End If
            Next
            
        End If
	' Following code commented is used to delete mails after
	' attachments were saved to disk.
        'Set nDoc2Remove = nDoc
    End If
    
    Set nDoc = View.GetNextDocument(nDoc)
    ' Following code commented is used to delete mails after
    ' attachments were saved to disk
    'If Not (nDoc2Remove Is Nothing) Then
    '    nDoc2Remove.Remove (True)
    '    Set nDoc2Remove = Nothing
    'End If
    
Wend

End Sub



©2001 - Richie Simonetti