Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Alternate way of sending email from Outlook to OneNote

Alternate way of sending email from Outlook to OneNote

Alternate way of sending email from Outlook to OneNote


I've scoured the internet to find an answer, but was unable to find an answer. Here is my problem:

My organisation has a size limitation in Outlook 2013 inbox size. As such, we have had to come up with possible solutions to saving these emails in a comprehesive way which is easy to manage and easy to find way.

I've heard that we could possibly automatically send our emails directly to OneNote 2013. I've used the "send to OneNote" button in Outlook, however I was wondering if anyone has any better solution that could automatically create a section named the email sender's name if it does not exist and copy the email to a new page.

The only VBA code I have found in my searches is to either create a OneNote page or search, however my very limited knowledge in XML does not allow me to go further.

Can anyone point me in the right direction?

Here is some of the code I've found:


Option Explicit

Sub CreateNewPage() ' Connect to OneNote 2010. ' To see the results of the code, ' you'll want to ensure the OneNote 2010 user ' interface is visible.
Dim OneNote As OneNote.Application
Set OneNote = New OneNote.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(2)
    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, xs2013
   ' Dim a As MSXML2.DOMDocument60
    Dim secDoc As MSXML2.DOMDocument60
    Set secDoc = New MSXML2.DOMDocument60

    If secDoc.LoadXML(sectionsXml) Then
        ' select the Section nodes
        Dim secNodes As MSXML2.IXMLDOMNodeList
        Debug.Print secDoc.DocumentElement.XML
        Dim soapNS
        soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'"
        secDoc.SetProperty "SelectionNamespaces", soapNS
        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, xs2013

            Dim doc As MSXML2.DOMDocument60
            Set doc = New MSXML2.DOMDocument60
            ' Load Page's XML into a MSXML2.DOMDocument object.
            If doc.LoadXML(outXML) Then
                ' Get Page Node.
                Dim pageNode As MSXML2.IXMLDOMNode
                soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'"
                doc.SetProperty "SelectionNamespaces", soapNS
                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 = "A Page Created from VBA"
                ' 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("Is this what I need to change?")

                newNode.appendChild cd

                ' Update OneNote with the new content.
                OneNote.UpdatePageContent doc.XML

                ' Print out information about the update.
                Debug.Print "A new page was created in "
                Debug.Print "Section " & sectionName & " in"
                Debug.Print "Notebook " & noteBookName & "."
                Debug.Print "Contents of new Page:"

                Debug.Print 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

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 OneNote.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, xs2013

' Use the MSXML Library to parse the XML.
Dim doc As MSXML2.DOMDocument60
Set doc = New MSXML2.DOMDocument60

If doc.LoadXML(notebookXml) Then
   Dim soapNS
   soapNS = "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'"
    doc.SetProperty "SelectionNamespaces", soapNS
    Set GetFirstOneNoteNotebookNodes = doc.DocumentElement.SelectNodes("//one:Notebook")
    Debug.Print doc.DocumentElement.XML

    Set GetFirstOneNoteNotebookNodes = Nothing
End If

End Function 

Thanks for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close