1

Currently, my VBA code creates a single file for each note. Here's some simplified sample code:

Sub saveNotes()
   Set myNote = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderNotes)
   For ibi = 1 To myNote.Items.Count
     fname = myNote.Items(ibi).Subject
     myNote.Items(ibi).SaveAs "C:\Temp\" & fname & ".txt", 0
   Next
End Sub

Instead of creating a single file for each note, I want to create a single file for all the notes. I'm looking for the most efficient method to concatenate these note's content and write them to a single file.

To give you an idea of the amount of data and how efficient it should be, there are hundreds of notes with an average size of 1024 chars.

4

1 回答 1

2

此代码将打开一个文本文件进行输出,并将每个音符的修改时间和正文写入文本文件。该文件将位于您的“我的文档”文件夹中,并将命名为 AllNotesYYYYMMDD.txt。您可能会根据您的操作系统以及您实际希望文件存储的位置更改该路径。

Sub SaveNotes()

    Dim fNotes As MAPIFolder
    Dim ni As NoteItem
    Dim sFile As String
    Dim lFile As Long

    Set fNotes = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderNotes)
    lFile = FreeFile
    sFile = Environ$("USERPROFILE") & "\My Documents\AllNotes" & Format(Date, "yyyymmdd") & ".txt"

    Open sFile For Output As lFile

    For Each ni In fNotes.Items
        Print #lFile, "Modified:" & vbTab & ni.LastModificationTime & vbNewLine & ni.Body
        Print #lFile, "-------------------------------"
    Next ni

    Close lFile

End Sub
于 2010-10-21T21:45:28.637 回答