Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detach attachment from Lotus Notes by VBA 1

Status
Not open for further replies.

StefanACC

Technical User
Sep 12, 2002
2
US
Hi!

Does anyone know, how attachments in Lotus Notes can be detached automatically by using VBA and saved to a certain directory?

Thanx a lot for your answer

Stefan
 
I've got the code at work. By answering this I'll put it to the front so I can see it tomorrow.
 
Hi!

Thanx for ansering me. I've already developed a code, but it does not work properly with exceptions. Can you put your code in front, so that I can use it?

:)))
 
This is the code I got:

Public Sub Notes()

sPathToSave = "Destination Path"
Dim View As Object 'New Domino.NotesView
Dim nDoc As Object 'Domino.NotesDocument
Const RICHTEXT = 1
Const EMBED_ATTACHMENT = 1454
Set s = CreateObject("Notes.Notessession") 'create notes session
Set db = s.GETDATABASE("", "") 'set db to database not yet named
Call db.openmail
Set View = db.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

Additionals:

This sets it look in a sub folder:
Set View = db.GETVIEW("Sub Folder")'replace the getview in the code

Moves to another folder, (actually moves a shortcut, remains in original folder):
ndoc.PutInFolder( "New Folder" )

And to remove from existing:
ndoc.RemovefromFolder( "Old Folder" )

Specify a specific db within notes:

Set db = s.GETDATABASE("server", "full address of mail box as in propetys")
so mine looks like
Set db = s.GETDATABASE("Orwell", "Mail\CS\Repoteam.nsf")

I've got a help file for Notes Sessions from VBA which should answer any questions. If you want it, mail a request to colin@kylua.com and I'll send it out to you


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top