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 : http://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:
‘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
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
If you have never used VBA in Outlook and want to try this out, here’s a quickstart:
- Start Outlook
- Hit ALT+F11. This launches VBA for Outlook.
- On the left will be the Project tree. Expand it until it looks like this:
- You should "ThisOutlookSesstion." Double click it
- You will see the code editor open to the right. Paste the code above into it:
- Hit F5 to run it. It goes pretty fast.
- 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,