Separate multiple attached files into individual notes documents

Use this agent code to break up the attachments into their own notes documents.

	Dim session As New NotesSession
	Dim db As NotesDatabase
	Set db = session.currentdatabase
	Dim doc As NotesDocument
	Set doc = session.DocumentContext	
	Dim x As Long
	Dim filenames() As String
	ReDim filenames(x) As String

	'create an array of all the filenames
	ForAll f In doc.items
		If"$FILE" Then
			If filenames(0) = "" Then
				filenames(x) = f.values(0)
				x = x + 1
				ReDim Preserve filenames(x) As String
				filenames(x) = f.values(0)
			End If
		End If	
	End ForAll

	'create the attachment sub docs (splitting up the attachments)
	Dim y,z As Integer
	Dim adoc As NotesDocument
	Dim neo As NotesEmbeddedObject
	For y = 0 To UBound(filenames)
		Set adoc = db.Createdocument()
		Call doc.CopyAllItems(adoc, False)
		ForAll i In doc.items    
			If<>"$FILE" Then Call adoc.RemoveItem(
		End ForAll
		adoc.form = "attachment"
		Call, True)

		'strip out the other attachments
		For z = 0 To UBound(filenames)
			If y = z Then
				'do nothing, leave this file
				'get it and remove it
				Set neo = adoc.Getattachment(filenames(z))
				If Not neo Is Nothing Then Call neo.Remove()
			End If
		Next z
		Call, True)
	Next y

Written by fbrefere001

Posted by fbrefere001 on Thursday May 13, 2021