Excel VBA und OneNote
27.10.2020 15:57:33
B.
folgendes Code-Beispiel möchte ich ausführen, aber es kommt immer ein Fehler dass "OneNote14.Application" nicht definiert ist. Eingebunden habe ich "OneNote 12.0 Object Library" und "OneNote 15.0 Object Library" sowie "Microsoft XML, v6.0", andere Versionen gibt es nicht zur Auswahl. Wie kann ich den Code anpassen? Nur die Zahl "14" zu ersetzen bringt keine Verbesserung.
Viele Grüße,
Betty
'Add the following references (adjust to our office version):
' - Microsoft OneNote 14.0 Object Library
' - Microsoft XML, v6.0
Sub ListOneNotePages()
' Original example is from http://code.msdn.microsoft.com/office/onenote-2010-retrieve-data-023e69c0
' License: Apache 2.0
' Modified to get all pages & content instead of the notebook list
' Connect to OneNote 2010.
' OneNote will be started if it's not running.
Dim oneNote As OneNote14.Application
Set oneNote = New OneNote14.Application
' Get the XML that represents the OneNote pages
Dim oneNotePagesXml As String
' oneNotePagesXml gets filled in with an XML document providing information
' about all OneNote pages.
' You want all the data. Thus you provide an empty string
' for the bstrStartNodeID parameter.
oneNote.GetHierarchy "", OneNote14.HierarchyScope.hsPages, oneNotePagesXml, xs2010
' Use the MSXML Library to parse the XML.
Dim doc As MSXML2.DOMDocument
Set doc = New MSXML2.DOMDocument
If doc.LoadXML(oneNotePagesXml) Then
' Find all the Page nodes in the one namespace.
Dim nodes As MSXML2.IXMLDOMNodeList
Set nodes = doc.DocumentElement.SelectNodes("//one:Page")
Dim node As MSXML2.IXMLDOMNode
Dim pageName As String
Dim SectionName As String
Dim PageContent As String
Dim temp As String
' Walk the collection of Pages.
' Read attribute values and write them
' out to the Immediate window of your VBA host.
For Each node In nodes
pageName = node.Attributes.getNamedItem("name").text
Debug.Print "Page name: "; vbCrLf & " " & pageName
Call oneNote.GetPageContent(GetAttributeValueFromNode(node, "ID"), PageContent, _
piBasic)
Debug.Print " content: " & PageContent
Next
Else
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."
Else
GetAttributeValueFromNode = node.Attributes.getNamedItem(attributeName).text
End If
End Function