2016-10-25 12 views
0

OneNote vbaで今日始まったので、試してみるためにネット上にサンプルプログラムがあります。 OneNote 2013を使用しているため、次のような基本的な変更が加えられました(ただし、OneNoteに新しいページが作成されます)。しかし、実行しようとするすべてのプログラムでエラーが返されます - 宣言されていない名前空間接頭辞への参照: )。 誰でも私がここで間違っていることを教えてもらえますか?私は、OCRを印刷画面用に実行してデータを元に戻すことができる割り当てを行う必要がありますが、それを開始するには基本を正しく理解することが良いことだと思っていました。それは一日を要しており、私はまだ何かを働かせることはできません。 ところで、Onenote 15.0オブジェクトライブラリとxml v6.0のリファレンスが作成されました。私はVBAの初心者ですし、どんな助けもありがとうございます。 「OneNoteの2013年 への接続」OneNote2013-宣言されていないネームスペースプレフィックスへの参照: 'one'エラー

サブCreateNewPage() は、コードの結果を確認するには、 はインターフェイス表示されている「あなたはOneNoteの2013ユーザー を確保したいと思うでしょう」。 薄暗いOneNoteのnode.Attributesもし文字列 としてOneNote.Application 設定のOneNote =新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(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, xs2013 

    Dim secDoc As MSXML2.DOMDocument60 
    Set secDoc = New MSXML2.DOMDocument60 

    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, 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 
       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("Text added to a new OneNote page via VBA.") 

       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 
     Else 
      MsgBox "OneNote 2013 Section nodes not found." 
     End If 
    Else 
     MsgBox "OneNote 2013 Section XML Data failed to load." 
    End If 
Else 
    MsgBox "OneNote 2013 XML Data failed to load." 
End If 

End Subの

プライベートファンクションGetAttributeValueFromNode(文字列としてMSXML2.IXMLDOMNode、attributeNameのようノード)として。 getNamedItem(attributeName)は何もしません GetAttributeValueFromNode = "見つかりませんでした。 エルス GetAttributeValueFromNode = node.Attributes.getNamedItem(attributeNameの).textの エンド エンド機能の場合

プライベートファンクションGetFirstOneNoteNotebookNodes(OneNote.ApplicationとしてOneNoteの)MSXML2.IXMLDOMNodeList

'として表すXMLを取得OneNoteノートブックが利用可能です。 Dim notebookXml As String 「OneNoteは、利用可能なOneNoteノートブックについて、情報を提供するXMLドキュメントでnotebookXmlを塗りつぶします。 」。 'すべてのデータが必要なので、bstrStartNodeIDパラメータには空の文字列 'を指定しています。 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 
    **Set GetFirstOneNoteNotebookNodes = doc.DocumentElement.SelectNodes("//one:Notebook")** 
Else 
    Set GetFirstOneNoteNotebookNodes = Nothing 
End If 

エンド機能

答えて

0

。 "one:"は名前空間ではなく、ただ一つの別名です。 1 = "http://schemas.microsoft.com/office/onenote/12/2004/onenote"

トップに:

XMLドキュメントはのxmlnsのようなものを持っている必要があります。

名前空間は、私が上記の太字で示したものです。
MSXML APIドキュメントをチェックして、クエリの実行時に名前空間を指定する方法を参照してください。

+0

ええ、正しい方向を指してくれてありがとう、たくさん読んでいましたが、今私はこのことをよく理解しています ps非常に遅い返事を申し訳ありません – erifnezorfss

関連する問題