使用VBA从Excel 2007自动化Onenote 2010?

Tap*_*nic 5 excel vba excel-2007 office-interop onenote

我想在Excel 2007中使用VBA来逐步完成大约500个收据,这些收据已转换为一个大型OneNote 2010笔记本.每个笔记本选项卡包含不同的收据 我需要从每个中获取相关详细信息(收据#,收货日期,金额,所有行项目数据,税金等),并且我想在Excel中使用该数据创建工作表.

数据是半结构化的,这意味着一旦我找到"订单号",我知道有一个空格字符,然后是订单号.但它可能是在不同的路线甚至推翻等等.但那没关系.我可以写VBA代码,这不是问题..

我认为它比数据输入更容易,或者比雇用某人手动键入所有这些更便宜...我不想去OCR路线,因为我需要准确性,我认为我可以从某种办公室之间的自动化Excel和OneNote.我无法使用OneNote 2010(从OneNote方面或Excel方面)找到任何自动化示例.另一个人可以指出我正确的方向吗?MSDN有Office和OneNote的开发者站点,但我必须盲目看不到任何示例甚至是对象模型!

Dan*_*and 5

MSDN 上的此 VBA 示例代码可能会对您有所帮助。我检索所有 OneNote 笔记本的列表。它是为 OneNote 2010 编写的,适用于我的 Office 2010 软件包,但我希望它也适用于 2007。

我已修改示例源以检索所有页面和页面内容。页面内容是 XML,因此您必须对其进行解析。

修改后的MSDN示例:

'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
Run Code Online (Sandbox Code Playgroud)


Han*_*son 3

我不知道有什么好的资源可以帮助您完成您想做的事情,但以下两篇文章提供了一些可以帮助您入门的信息:

使用 OneNote 对象模型创建 OneNote 2010 扩展

OneNote 2007 中面向开发人员的新增功能(第 1 部分,共 2 部分)

为了找到更多信息,我建议Microsoft.Office.Interop.OneNote您在 .Net 上进行谷歌搜索,希望您能找到很多关于 .Net 的问题,即使它可能并不理想,但至少可以给您一些提示。