0
Excel에서 VBA를 사용하여 스프레드 시트에서 셀을 복사하여 OneNote에 그림으로 붙여 넣으려고합니다. 이것이 가능한가?VBA를 사용하여 Excel 그림을 OneNote에 붙여 넣기
아래 코드는 제가 수행 한 코드입니다 (엑셀 셀 복사 부분은 포함하지 않습니다). XML에 대한 경험이 거의 없으며 XML로 코딩해야 할 부분을 정확히 알지 못합니다. 내가 코드를 실험하고
이미지에있다 OneNote의
의 특정 위치에 이미지를 삽입이함께했다
Sub PasteToOneNote()
' Connect to OneNote 2010.
' OneNote will be started if it's not running.
Dim oneNote As OneNote14.Application
Set oneNote = New OneNote14.Application
Dim OpenedFile As String
'Open OneNote file and creates an output ID to call on the file (OpenedFile)
oneNote.OpenHierarchy bstrPath:="File Path", _
bstrRelativeToObjectID:="", _
pbstrObjectID:=OpenedFile
'Use the output ID from OpenHierarchy to open OneNote file
oneNote.NavigateTo bstrHierarchyObjectID:=OpenedFile, _
bstrObjectID:="", _
fNewWindow:=False
Dim XMLSectionFile As String
'OneNote's GetHierarchy method allows you to get meta-data and data about the OneNote Notebooks.
'Takes data and puts into XML output
oneNote.GetHierarchy bstrStartNodeId:=OpenedFile, _
hsScope:=hsPages, _
pbstrHierarchyXMLOut:=XMLSectionFile
'Use the MSXML Library to parse the XML
Dim secDoc As MSXML2.DOMDocument
Set secDoc = New MSXML2.DOMDocument
If secDoc.LoadXML(XMLSectionFile) Then
'Select all section nodes
Dim pageNodes As MSXML2.IXMLDOMNodeList
Set pageNodes = secDoc.DocumentElement.SelectNodes("//one:Page")
'Loop through each page to find the page that has the same title as "ABC" then paste picture
Dim node As MSXML2.IXMLDOMNode
Dim pageName As String
Dim pageID As String
For Each node In pageNodes
pageName = node.Attributes.getNamedItem("name").Text
If pageName = "ABC" Then
'Get pageID and load page's XML output
pageID = node.Attributes.getNamedItem("ID").Text
Dim XMLPageFile As String
oneNote.GetPageContent bstrPageID:=pageID, _
pbstrPageXMLout:=XMLPageFile
' Load Page's XML into a MSXML2.DOMDocument object.
Dim pageDoc As MSXML2.DOMDocument
Set pageDoc = New MSXML2.DOMDocument
If pageDoc.LoadXML(XMLPageFile) Then
' Get Page Node.
Dim pagenode2 As MSXML2.IXMLDOMNode
Set pagenode2 = pageDoc.SelectSingleNode("//one:Page")
Dim newElement As MSXML2.IXMLDOMElement
Dim newNode As MSXML2.IXMLDOMNode
' Create Outline node.
Set newElement = pageDoc.createElement("one:Outline")
Set newNode = pagenode2.appendChild(newElement)
' Create OEChildren.
Set newElement = pageDoc.createElement("one:OEChildren")
Set newNode = newNode.appendChild(newElement)
' Create OE.
Set newElement = pageDoc.createElement("one:OE")
Set newNode = newNode.appendChild(newElement)
' Create TE.
Set newElement = pageDoc.createElement("one:T")
Set newNode = newNode.appendChild(newElement)
' Add the image for the Page's content.
??
oneNote.UpdatePageContent pageDoc.XML
End If
End If
Next
End If
End Sub