|
求助各位大师
如下代码可以实现在OneNote中批量新建页面,能不能实现在页面中自动添加内容呢?
- Sub OneNotePagemaker()
- Dim oneNote As oneNote.Application
- Set oneNote = New oneNote.Application
- Dim MyRange As Excel.Range
- Dim Fname As String
- Fname = ThisWorkbook.Path & "\test.one"
- Dim idString As String
- oneNote.OpenHierarchy Fname, "", idString
- Dim pageTitle As Range
- Set MyRange = Sheet1.Range("A:A")
- For Each pageTitle In MyRange
- If Not pageTitle.Formula = "" Then
- Dim newPage As String
- oneNote.CreateNewPage idString, newPage
- Dim pageContent As String
- oneNote.GetPageContent newPage, pageContent
- Dim pageXml As Object
- Set pageXml = CreateObject("MSXML2.DOMDocument")
- pageXml.LoadXML (pageContent)
- Dim pageElement As MSXML2.IXMLDOMElement
- Set pageElement = pageXml.DocumentElement
- Dim CDATAParent As MSXML2.IXMLDOMNode
- Set CDATAParent = pageElement.ChildNodes.Item(2).FirstChild.FirstChild
- Dim oldDataNode As MSXML2.IXMLDOMNode
- Set oldDataNode = pageElement.ChildNodes.Item(2).FirstChild.FirstChild.FirstChild
- Dim newNameNode As MSXML2.IXMLDOMCDATASection
- Set newNameNode = pageXml.createCDATASection(pageTitle.Formula)
- CDATAParent.RemoveChild oldDataNode
- CDATAParent.appendChild newNameNode
- oneNote.UpdatePageContent pageXml.XML
- End If
- Next
- End Sub
复制代码
|
|