An Outlook routine to export sticky notes and then import them to OneNote

Bill was looking for a way to move his Outlook sticky notes to OneNote. Way back when, I wrote an addin for Outlook 2007 that would export Outlook 2007 notes to OneNote 2007 at : https://blogs.msdn.com/b/descapa/archive/2007/02/14/export-your-outlook-notes-to-onenote.aspx. I have never had time to update it to 2010, and Bill had a better idea anyway.

 

Here's what he had to say about his VBA code:

 

"Here’s the VBA code that I stored in Outlook.  This creates a main c:\MyOutlookNotes folder, then subfolders by Category.

File names are based on note Subject.  I then used your 2010 .txt to OneNote transfer program, doing each folder separately to maintain tabs as my categories in OneNote.

I needed to massage the note subject as some had (#)  appended on the end for some reason. Also some of my subjects had PDA folder locations appended to the front, which I removed from the file name.

Probably a more efficient way exists to code this, but I don’t plan on using this again.

Hope this is helpful for someone."

 

He chose to export his Outlook sticky notes to text format, then use my text importer to import them. He made one other change - he has sorted his Outlook notes by category, and exports all the notes that have the same category to the same folder on the hard drive. He wrote a short macro for Outlook to do this, so you don't even need to install a utility to get his routine. Here's the code:

 

Sub ExportNotes()

'WJ Pommersheim Dec 23, 2010

'Exports all of Outlook Notes (text) into text files,

'with separate folders for each category.

'These will be in c:\MyOutlookNotes, with subfolders by category

Dim fname As String, ibi As Integer

Dim myNote As Folder, myItem As NoteItem

Dim TopDir As String, TheCat As String

    TopDir = "c:\MyOutlookNotes\"

    If Len(Dir(TopDir, vbDirectory)) = 0 Then MkDir TopDir 'create top directory if necessary

    Set myNote = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderNotes)

    For ibi = 1 To myNote.Items.Count

        ChDir TopDir

        If myNote.Items(ibi).Class = olNote Then    'Text notes only

            Set myItem = myNote.Items(ibi)

            TheCat = myItem.Categories

            fname = myItem.Subject

            If Right(fname, 1) = ")" Then fname = Left(fname, Len(myItem.Subject) - 3)  'Remove (#) if present

            fname = Right(fname, Len(fname) - InStr(fname, "\"))    'Remove folder text if present (old PDA format)

            If Len(Dir(TheCat, vbDirectory)) = 0 Then MkDir TheCat 'Need to create directory

            ChDir TopDir & TheCat

            Open fname & ".txt" For Output As #1  'This only saves note text, whereas item.SaveAs adds mod date, category

            Print #1, myItem.Body

            Close #1

        End If

   Next

End Sub

 

If you have never used VBA in Outlook and want to try this out, here's a quickstart:

  1. Start Outlook
  2. Hit ALT+F11. This launches VBA for Outlook.
  3. On the left will be the Project tree. Expand it until it looks like this:
  4. clip_image001
    1. You should "ThisOutlookSesstion." Double click it
    2. You will see the code editor open to the right. Paste the code above into it:
  5. clip_image002
  1. Hit F5 to run it. It goes pretty fast.
  2. If you want to step through it line by line, use F8.

 

That's it. When you are done, you will have a c:\MyOutlookNotes folder with all your notes in TXT format. Now you can import them to OneNote.

 

Thanks for the code, Bill!

 

Questions, comments, concerns and criticisms always welcome,

John