Last reviewed on October 3, 2012   —  6 Comments

Applies to: Microsoft Outlook 2010 and OneNote 2010

This macro still needs some work, specifically in testing for attachments and copying them to the page. It may also need more fields added and useless fields removed (which is no big deal). I am testing this only with Outlook 2010; it may work with Outlook 2007 versions if OneNote references are changed. It errors in Outlook 2013.

To use, you need to set a Reference to OneNote14 and XML in Tools, Reference.
Remember to set the references to OneNote and XML libraries

Select one or more Journal entries and run the macro. The selected journal items are added to OneNote, one journal entry per page.

By linking Contacts to OneNote (in the same OneNote section), you can make the journal entries subpages of the contacts.

Sample printout of journal entry in OneNote

Sub CopyJournalToOnenotePage()

Dim oJournal As Outlook.JournalItem
Dim oContact As Outlook.ContactItem
Dim spLinks As Outlook.Links
Dim spLink As Outlook.Link

Dim strJournal As String
Dim strContact As String

Set Selection = ActiveExplorer.Selection

For Each oJournal In Selection
Set spLinks = oJournal.Links

strContact = ""

For Each spLink In spLinks
    Set oContact = spLink.Item
    strContact = oContact.FullName & "; " & strContact

Set spLink = Nothing

strJournal = "<b>Contact : </b>" & vbTab & strContact & vbCrLf & _
    "<b>Entry Type:</b>" & vbTab & oJournal.Type & vbCrLf & _
    "<b>Categories:</b>" & vbTab & oJournal.Categories & vbCrLf & _
    "<b>Company:</b>" & vbTab & oJournal.Companies & vbCrLf & _
    "<b>Start Time:</b>" & vbTab & oJournal.Start & vbCrLf & _
    "<b>End Time:</b>" & vbTab & oJournal.End & vbCrLf & _
    "<b>Duration:</b>" & vbTab & oJournal.Duration & " minutes" & vbCrLf & _
    "<b>Billing:</b>" & vbTab & oJournal.BillingInformation & vbCrLf & _
    "<b>Mileage:</b>" & vbTab & oJournal.Mileage & vbCrLf & _
    "<b>Last modified: </b>" & vbTab & oJournal.LastModificationTime & vbCrLf & _
    "<b>Notes: </b>" & vbTab & vbTab & oJournal.Body & vbCrLf & vbCrLf & "---- End Record ---"
    Dim oneNote As OneNote14.Application
    Set oneNote = New OneNote14.Application
    ' Get all of the Notebook nodes.
    Dim nodes As MSXML2.IXMLDOMNodeList
    Set nodes = GetFirstOneNoteNotebookNodes(oneNote)
    If Not nodes Is Nothing Then
        ' Get the first OneNote Notebook in the XML document.
        Dim node As MSXML2.IXMLDOMNode
        Set node = nodes(0)
        Dim noteBookName As String
        noteBookName = node.Attributes.getNamedItem("name").Text
        ' Get the ID for the Notebook so the code can retrieve
        ' the list of sections.
        Dim notebookID As String
        notebookID = node.Attributes.getNamedItem("ID").Text
        ' Load the XML for the Sections for the Notebook requested.
        Dim sectionsXml As String
        oneNote.GetHierarchy notebookID, hsSections, sectionsXml, xs2010
        Dim secDoc As MSXML2.DOMDocument
        Set secDoc = New MSXML2.DOMDocument
        If secDoc.LoadXML(sectionsXml) Then
            ' select the Section nodes
            Dim secNodes As MSXML2.IXMLDOMNodeList
            Set secNodes = secDoc.DocumentElement.SelectNodes("//one:Section")
            If Not secNodes Is Nothing Then
                ' Get the first section.
                Dim secNode As MSXML2.IXMLDOMNode
                Set secNode = secNodes(0)
                Dim sectionName As String
                sectionName = secNode.Attributes.getNamedItem("name").Text
                Dim sectionID As String
                sectionID = secNode.Attributes.getNamedItem("ID").Text
                ' Create a new blank Page in the first Section
                ' using the default format.
                Dim newPageID As String
                oneNote.CreateNewPage sectionID, newPageID, npsDefault
                ' Get the contents of the page.
                Dim outXML As String
                oneNote.GetPageContent newPageID, outXML, piAll, xs2010
                Dim doc As MSXML2.DOMDocument
                Set doc = New MSXML2.DOMDocument
                ' Load Page's XML into a MSXML2.DOMDocument object.
                If doc.LoadXML(outXML) Then
                    ' Get Page Node.
                    Dim pageNode As MSXML2.IXMLDOMNode
                    Set pageNode = doc.SelectSingleNode("//one:Page")

                    ' Find the Title element.
                    Dim titleNode As MSXML2.IXMLDOMNode
                    Set titleNode = doc.SelectSingleNode("//one:Page/one:Title/one:OE/one:T")
                    ' Get the CDataSection where OneNote store's the Title's text.
                    Dim cdataChild As MSXML2.IXMLDOMNode
                    Set cdataChild = titleNode.SelectSingleNode("text()")
                    ' Change the title in the local XML copy.
                    cdataChild.Text = oJournal.Subject
                    ' Write the update to OneNote.
                    oneNote.UpdatePageContent doc.XML
                    Dim newElement As MSXML2.IXMLDOMElement
                    Dim newNode As MSXML2.IXMLDOMNode
                    ' Create Outline node.
                    Set newElement = doc.createElement("one:Outline")
                    Set newNode = pageNode.appendChild(newElement)
                    ' Create OEChildren.
                    Set newElement = doc.createElement("one:OEChildren")
                    Set newNode = newNode.appendChild(newElement)
                    ' Create OE.
                    Set newElement = doc.createElement("one:OE")
                    Set newNode = newNode.appendChild(newElement)
                    ' Create TE.
                    Set newElement = doc.createElement("one:T")
                    Set newNode = newNode.appendChild(newElement)
                    ' Add the text for the Page's content.
                    Dim cd As MSXML2.IXMLDOMCDATASection
                    Set cd = doc.createCDATASection(strJournal)

                    newNode.appendChild cd
                    ' Update OneNote with the new content.
                    oneNote.UpdatePageContent doc.XML

                End If
                MsgBox "OneNote 2010 Section nodes not found."
            End If
            MsgBox "OneNote 2010 Section XML Data failed to load."
        End If
        MsgBox "OneNote 2010 XML Data failed to load."
    End If
Set oJournal = Nothing
Set oContact = Nothing

End Sub

Private Function GetAttributeValueFromNode(node As MSXML2.IXMLDOMNode, attributeName As String) As String
    If node.Attributes.getNamedItem(attributeName) Is Nothing Then
        GetAttributeValueFromNode = "Not found."
        GetAttributeValueFromNode = node.Attributes.getNamedItem(attributeName).Text
    End If
End Function

Private Function GetFirstOneNoteNotebookNodes(oneNote As OneNote14.Application) As MSXML2.IXMLDOMNodeList
    ' Get the XML that represents the OneNote notebooks available.
    Dim notebookXml As String
    ' OneNote fills notebookXml with an XML document providing information
    ' about what OneNote notebooks are available.
    ' You want all the data and thus are providing an empty string
    ' for the bstrStartNodeID parameter.
    oneNote.GetHierarchy "", hsNotebooks, notebookXml, xs2010
    ' Use the MSXML Library to parse the XML.
    Dim doc As MSXML2.DOMDocument
    Set doc = New MSXML2.DOMDocument
    If doc.LoadXML(notebookXml) Then
        Set GetFirstOneNoteNotebookNodes = doc.DocumentElement.SelectNodes("//one:Notebook")
        Set GetFirstOneNoteNotebookNodes = Nothing
    End If
End Function


  1. Tim says

    Hi Diane, any chance you have a way to log a OneNote entry into the Journal in Outlook 2010? I'd like to see that when I look at my Journal, it shows that I took notes of a meeting in OneNote. Thanks, Tim

  2. Chris. says

    Hi Diane, this is great :)

    did you ever update this to take attachments?

    Also, is there a way to set the one-note date, time etc from the Journal note?


    • Diane Poremsky says

      No, I haven't had time to figure out how to do attachments with it. I haven't done much (read: none) programming in OneNote so I'm not as familiar with the features. As for dates, I have no idea. We can get the date from outlook easily enough but i don't know if the date field is writable via vba in onenote.

  3. Chris. says

    Thanks very much for your reply Diane, you've given me a great starter. If I find myself with some time to look at this and come up with a solution I'll let you know


Leave a Reply

Please post long or more complicated questions at OutlookForums by

If the Post Comment button disappears, press your Tab key.