开发者

Creating a single file from multiple notes in Outlook VBA

开发者 https://www.devze.com 2023-01-21 15:05 出处:网络
Currently, my VBA code creates a single file for each note. Here\'s some simplified sample code: Sub saveNotes()

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 ib开发者_Go百科i = 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.


This code will open a text file for output and write the modified time and body of each note into the text file. The file will be in your My Documents folder and will be named AllNotesYYYYMMDD.txt. You might change that path based on your operating system and where you actually want the file stored.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消