Hi @周林 陈,
Yes, there is another option to copy a picture from Excel to OneNote using VBA. You can use the CopyPicture
method to copy the picture as it appears in Excel, and then paste it into OneNote.
Here's an example code snippet to get you started:
Sub CopyExcelPictureToOneNote()
' Copy the picture in Sheet1 to the clipboard
Sheet1.Range("A1:D5").CopyPicture xlScreen, xlBitmap
' Get a reference to the OneNote application
Dim onApp As OneNote.Application
Set onApp = CreateObject("OneNote.Application")
' Open a new page in the default notebook
Dim onSection As OneNote.Section
Set onSection = onApp.GetHierarchy(Null, hsPages, False).Pages(1).ParentSection
Dim onPage As OneNote.Page
Set onPage = onSection.AddPage(Null)
' Paste the picture into the page
onPage.Placeholder(Null, False).Select
onApp.ActiveWindow.CurrentPage.Paste
onApp.ActiveWindow.CurrentPage.RefreshContent
End Sub
In this example, the CopyPicture
method is used to copy the range "A1:D5" as it appears on the screen (using the xlScreen
and xlBitmap
arguments). The picture is then pasted into a new page in OneNote using the Paste
method. Note that this code requires a reference to the OneNote type library, which you can add in the VBA editor by going to Tools > References and selecting "Microsoft OneNote 16.0 Object Library" (or a similar version, depending on your installation).
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.