次の例は現在のデータベース内の文書から文書コレクションを作成します。このコレクションには、件名フィールドに「test」という語を含む文書だけを組み込みます。Add メソッドのパラメータには、NotesDocument を指定します。作成したコレクションはファイル filename にエクスポートします。
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim stream As NotesStream
Dim exporter As NotesDXLExporter
Dim nc As NotesNoteCollection
Dim dc As NotesDocumentCollection
Dim i As Integer
Dim c As Integer
Dim doc As NotesDocument
Dim subj As Variant
Dim filename As String
REM Create an empty note collection
REM from the current database
Set db = session.CurrentDatabase
path$ = "c:¥dxl¥"
filename$ = Left(db.FileName, Len(db.FileName) - 3) & "dxl"
filename$ = path$ & filename$
Set nc = db.CreateNoteCollection(False)
Call nc.BuildCollection
c = nc.Count
REM Search for specific documents
Set dc = db.AllDocuments
Set doc = dc.GetFirstDocument
While Not (doc Is Nothing)
subj = doc.GetItemValue("Subject")
If Not findTest(subj(0))(0) = 0 Then
REM Modify the collection
Call nc.Add(doc)
End If
Set doc = dc.GetNextDocument(doc)
Wend
REM Export note collection as DXL
Set stream = session.CreateStream
If Not stream.Open(filename) Then
Messagebox "Cannot open " & filename,, "Error"
Exit Sub
End If
Call stream.Truncate
Set exporter = session.CreateDXLExporter(nc, stream)
Call exporter.Process
If nc.Count - c > 0 Then
Messagebox Cstr(nc.Count-c) & " documents added", , _
filename
End If
End Sub
Function findTest(value As String)
findTest = Evaluate( "@Contains (""" _
+ Ucase$(value) _
+ """; """ _
+ "TEST"+""") ")
End Function