2012-03-14 18 views
0

OneNote 2010でノートブックを追加する方法を理解しようとしています。新しいノートブックを追加するためにUpdateHiearchy APIを使用する方法を示すコードサンプルは見つかりません。私はVB6アプリケーションからこれをやろうとしています。私はVBからxmlを使うのが初めてです。次のように コードは次のとおりです。UpdateHiearchyをVBコードで使用してOneNoteでノートブックを作成する

Private Function GetFirstOneNoteNotebookNodes(oneNote As OneNote14.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, xs2010 

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

    Dim elem As MSXML2.IXMLDOMElement 

    If doc.loadXML(notebookXml) Then 
     ' Here is search for a notebook that i know is not there.  mvarpAssignment.pClient.Name is a program variable that contains a text name. 
     Set GetFirstOneNoteNotebookNodes = doc.documentElement.selectNodes("//one:Notebook[@name='" & mvarpAssignment.pClient.Name & "']") 
' I test the length for zero to see if anything was returned:   
If GetFirstOneNoteNotebookNodes.Length = 0 Then 
' I want to create a notebook, so i beleive i need to add an element to the xml returned from the GetHiearchy API:   
Set elem = doc.createElement("ROC") 
      doc.documentElement.appendChild elem 
'I print out the xml and i can see the element added at the end of the xml document.    
      Debug.Print doc.XML 

「次のステップは、UpdateHiearchyのAPIを呼び出すことであろうが、私はAPIに渡すwhchオブジェクトに同様に、私は途方に暮れています。私が試したすべてが失敗する。私は明らかにこれを十分に理解していませんが、コードサンプルやノートブックを追加する方法を説明するテキストは見つかりません。どんなヘルプや情報へのリンクがあれば、大いに感謝します!

答えて

0

私はついにこれを実現させました。私は2つのことが間違っていた、パスは、階層を更新する前に定義する必要があります。 GetSpecialLocation APIを使用する必要があります。また、属性名は大文字小文字ではなく、小文字ではなくラクダの大文字小文字を持っています。私は元のコードから他の変更のcopupleを投稿したが、私のアプリケーションのためのtismore。関心のある人のための改訂コード:

Private Function GetClientOneNoteNotebookNode(oneNote As OneNote14.Application,  ClientName As String) As MSXML2.IXMLDOMNodeList 
Dim notebookXml As String 
Dim doc As MSXML2.DOMDocument 
Dim elem As MSXML2.IXMLDOMElement 
Dim newNotebookPath As String 
Dim defaultNotebookFolder 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, xs2010 
' Use the MSXML Library to parse the XML. 
Set doc = New MSXML2.DOMDocument 
If doc.loadXML(notebookXml) Then 
Set GetClientOneNoteNotebookNode = doc.documentElement.selectNodes("//one:Notebook[@name='" & ClientName & "']") 
If GetClientOneNoteNotebookNode.Length = 0 Then 
'Get the default location for the notebooks 
oneNote.GetSpecialLocation slDefaultNotebookFolder, defaultNotebookFolder 
newNotebookPath = defaultNotebookFolder + "\\" + ClientName 
'Create new notebook for cleint 
Set elem = doc.createElement("one:Notebook") 
elem.setAttribute "name", ClientName 
elem.setAttribute "path", newNotebookPath 
' add new elelement to the document tree 
doc.documentElement.appendChild elem 
oneNote.UpdateHierarchy doc.XML 
End If 
Else 
Set GetClientOneNoteNotebookNode = Nothing 
End If 
End Function 
関連する問題