Skip to content

Instantly share code, notes, and snippets.

@swbuehler
Last active September 9, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swbuehler/df19a6857d8e7b4bf24b024aae8a0e08 to your computer and use it in GitHub Desktop.
Save swbuehler/df19a6857d8e7b4bf24b024aae8a0e08 to your computer and use it in GitHub Desktop.
Changes date of a OneNote page depending on information provided in "Sent" email header from Outlook or a table with "Date/Time" header (VBA). Requires a "LocalTimeToUTC()" function provided elsewhere.
Sub CorrectDateOnPage()
Dim appOneNote As New OneNote.Application
Dim pageXML As New MSXML2.DOMDocument60
Dim pageContent As String
Dim clipboard As New MSForms.DataObject
Dim tNodes As IXMLDOMNodeList
Dim tNode As IXMLDOMNode
thisPage = appOneNote.Windows.CurrentWindow.CurrentPageId
appOneNote.GetPageContent thisPage, pageContent, piAll, xs2013
pageXML.LoadXML pageContent
pageXML.SetProperty "SelectionNamespaces", "xmlns:one='http://schemas.microsoft.com/office/onenote/2013/onenote'"
' Find the date the email was sent, or look for "Date/Time" table row
Set tNodes = pageXML.DocumentElement.SelectNodes("//one:T")
For i = 1 To tNodes.Length
If InStr(1, tNodes.Item(i).Text, ">Sent", vbTextCompare) > 1 Or tNodes.Item(i).Text = "Date/Time" Then
datesent = tNodes.Item(i + 1).Text
Exit For
End If
Next i
If tNodes(i).Text = "Date/Time" Then
theDate = CDate(datesent)
Else
theDate = CDate(Right(datesent, Len(datesent) - InStr(1, datesent, " ", vbTextCompare) + 1))
End If
isodatestring = Format(LocalTimeToUTC(theDate), "yyyy-mm-ddThh:mm:ss.000Z")
Debug.Print isodatestring
Set tNode = pageXML.DocumentElement.SelectSingleNode("//one:Page")
tNode.Attributes.getNamedItem("dateTime").Text = isodatestring
appOneNote.UpdatePageContent pageXML.XML, , xs2013
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment