- Sync your iPhone notes with Outlook and make sure all your notes are in there.
- In Outlook, go to Tools > Macro > Visual Basic Editor (Alt+F11)
You will see that Microsoft Visual Basic has opened.
- There should now be a blank document where you can type code. If you do not see this, expand the Project1 tree on the left (in the Project panel) until you get to ThisOutlookSession, and double click it.
- Paste the code at the bottom of this post after any existing code (you may or may not have code there), and save the document.
- Close Microsoft Visual Basic.
- Allow the macro to run by doing one of the following:
- To temporarily allow all macros to run (easier), do the following:
- Go to Tools > Macro > Security...
- Change the Security Level to Medium or Low.
- Don't forget to change it back to High after you are done with this!
- To create a certificate that will be used to sign your macro (safer), do the following:
- Start > All Programs > Microsoft Office > Microsoft Office Tools > Digital Certificate for VBA Projects
- Follow the steps to create a certificate, and name it whatever you want.
- Open Microsoft Visual Basic again (Alt+F11) in Outlook.
- Tools > Digital Signature > Choose...
- Choose the certificate you just created.
- Press OK and close Microsoft Visual Basic.
- When prompted in the next steps if you want to run this macro, remember to allow it and to choose to trust this publisher.
- Tools > Macro > Macros... (Alt+F8)
- Choose ThisOutlookSession.exportNotesToEvernote
- Press Run.
- Choose File > Import > Evernote Export Files...
- Choose the OutlookNotes.enex file located in My Documents.
Here's the code for Microsoft Visual Basic:
Function pad(ByVal n, ByVal l) As String pad = Right("000000000" & n, l) End Function Function enDateTime(ByVal d) As String ' Sample date: 20101021T205209Z enDateTime = Year(d) & pad(Month(d), 2) & pad(Day(d), 2) & "T" & pad(Hour(d), 2) & pad(Minute(d), 2) & pad(Second(d), 2) & "Z" End Function Function HTMLEncode(ByVal Text As String) As String ' Slightly modified version of http://www.devx.com/vb2themax/Tip/19162 Dim i As Integer Dim acode As Integer Dim repl As String HTMLEncode = Text For i = Len(HTMLEncode) To 1 Step -1 acode = AscW(Mid$(HTMLEncode, i, 1)) Select Case acode Case 32 ' repl = " " Case 34 repl = """ Case 38 repl = "&" Case 60 repl = "<" Case 62 repl = ">" Case 32 To 127 ' don't touch alphanumeric chars Case 13 ' don't touch new lines Case 10 ' don't touch new lines Case Else repl = "&#" & CStr(acode) & ";" End Select If Len(repl) Then HTMLEncode = Left$(HTMLEncode, i - 1) & repl & Mid$(HTMLEncode, _ i + 1) repl = "" End If Next End Function Sub exportNotesToEvernote() ' http://www.sensefulsolutions.com/2010/10/import-iphone-notes-to-evernote-via.html FileName = Environ$("USERPROFILE") & "\My Documents\OutlookNotes.enex" File = FreeFile() Open FileName For Output As File Print #File, "<?xml version=""1.0"" encoding=""UTF-8""?>" _ & "<!DOCTYPE en-export SYSTEM ""http://xml.evernote.com/pub/evernote-export.dtd"">" _ & "<en-export export-date=""" & enDateTime(Now) & """ application=""Evernote/Windows"" version=""3.5"">" Tag = "" ' Uncomment this line to set a tag for all notes and (replace the My Tag with the name of the tag you want) ' Tag = "<tag>" & xmlEscape("iPhone Notes") & "</tag>" Set Notes = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderNotes) For i = 1 To Notes.Items.Count Set note = Notes.Items(i) Subject = note.Subject Subject = Left(Subject, 64) Subject = HTMLEncode(Subject) Body = note.Body Body = HTMLEncode(Body) Body = Replace(Body, vbNewLine, "<" & "br/>" & vbLf) Print #File, "<note><title>" & Subject & "</title><content>" _ & "<![CDATA[<?xml version=""1.0"" encoding=""UTF-8""?>" _ & "<!DOCTYPE en-note SYSTEM ""http://xml.evernote.com/pub/enml2.dtd"">" _ & "<en-note>" & Body _ & "</en-note>]]></content><created>" & enDateTime(note.CreationTime) & "</created><updated>" & enDateTime(note.CreationTime) & "</updated>" & Tag & "</note>" ' uses the note's creation time for both the modification and creation time in Evernote Next Print #File, "</en-export>" Close #File End Sub
Understanding how the dates work:
When you look at notes on the iPhone, you only see their modification date. Behind the scenes, Apple is also storing their creation date, though. When you import the notes to Outlook, it will set the creation date to the time that Apple recorded as the note being created, and it will set the modification date to the current time. Thus, the modification time in Outlook is useless, and there is no way (using Outlook) to get the same exact dates you see on the iPhone. For this reason, I chose to completely ignore Outlook's modification date and I use the creation date for both the created and modification dates in Evernote.