在 Outlook VBA 中从多个便笺创建单个文件

发布于 2024-09-28 12:47:20 字数 443 浏览 4 评论 0原文

目前,我的 VBA 代码为每个笔记创建一个文件。下面是一些简化的示例代码:

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

我想为所有笔记创建一个文件,而不是为每个笔记创建一个文件。我正在寻找最有效的方法来连接这些笔记的内容并将它们写入一个文件。

为了让您了解数据量及其效率,有数百个注释,平均大小为 1024 个字符。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燃情 2024-10-05 12:47:20

此代码将打开一个文本文件进行输出,并将每个笔记的修改时间和正文写入文本文件。该文件将位于您的“我的文档”文件夹中,并命名为 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文