2016-10-25 2 views
0

OneNote vba로 오늘 시작되었으므로, 시도 할 그물을 통해 샘플 프로그램이 있습니다. OneNote 2013을 사용하면 다음과 같은 기본 변경 사항 (OneNote에서 새 페이지 만들기)을 만들 수 있습니다. 그러나 실행하려고하는 모든 프로그램에서 오류를 반환합니다. 선언되지 않은 네임 스페이스 접두어에 대한 참조 : '한 가지 오류 (굵게 표시된 줄). 누구든지 내가 뭘 잘못하고 있는지 알려주실 수 있습니까? 나는 printscreen을 위해 OCR을 실행할 수 있고 데이터를 Excel로 되 돌릴 수있는 과제를 얻어야 만하지만, 기본으로 올바른 것을 얻는 것이 좋을 것이라고 생각했다. 그것은 하루 종일 걸렸고 나는 여전히 어떤 것도 만들 수 없습니다. 그런데 Onenote 15.0 오브젝트 라이브러리 및 xml v6.0에 대한 참조가 작성되었습니다. 나는 VBA에서 초보자이며 어떤 도움을 주셔서 감사합니다. 'OneNote를 2013 에 연결'OneNote2013- 선언되지 않은 네임 스페이스 접두어에 대한 참조 : 'one'오류

하위 CreateNewPage() 코드의 결과를 보려면, 인터페이스 볼 수 있습니다 '당신은 OneNote의 2013 사용자 보장 할 것이다'. 희미한 OneNote를 node.Attributes 만약 문자열 로 (문자열로 MSXML2.IXMLDOMNode, 여기서 attributeName으로 노드) 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 

최종 하위

개인 기능 GetAttributeValueFromNode으로. getNamedItem (attributeName) Nothing이면 GetAttributeValueFromNode = "찾을 수 없습니다." 다른 이 GetAttributeValueFromNode = node.Attributes.getNamedItem (여기서 attributeName)는 .text가 가 최종 기능이

이 MSXML2.IXMLDOMNodeList으로

개인 기능 GetFirstOneNoteNotebookNodes (OneNote.Application으로 OneNote를가)

'얻기 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 :"은 네임 스페이스가 아니며, 하나의 별칭 일뿐입니다. 한 = "http://schemas.microsoft.com/office/onenote/12/2004/onenote"

상단 :

하여 XML 문서의 xmlns 같은 것을해야한다.

네임 스페이스는 위에서 굵게 표시 한 것입니다.
MSXML API 문서를 확인하여 쿼리 할 때 네임 스페이스를 지정하는 방법을 확인하십시오.

+0

예, 올바른 방향을 가리켜 주셔서 감사합니다. 지금은 이걸 더 잘 이해하고 있습니다. ps 매우 늦게 답장을 보내 주셔서 죄송합니다. – erifnezorfss