简体   繁体   中英

Pasting an image from clipboard using VBA (Excel)

I am trying to write a macro that allows the user to paste an image (like a screenshot) onto my spreadsheet.

I came across this solution but I do not understand it ( Paste an image from clipboard to a cell in Excel )

What I need to achieve: 1) User takes a screenshot, like with Snipping Tool 2) Allow user to paste that image in the clipboard onto a specified area (and size) on Sheet 1, aligned to cell J55. 3) Also later, the user should be able to re-use that image (another macro button that pastes that image onto another sheet)

I tried a few codes, like:

 If My.Computer.Clipboard.ContainsImage() Then Dim grabpicture = My.Computer.Clipboard.GetImage() PictureBox1.Image = grabpicture End If 

but I get an error at "Dim grabpicture".

We are using Office 2010.

The code snippet you were trying is not VBA. Here's how you would paste from the clipboard in Excel-VBA:

 Sheet1.Paste Destination:= Sheet1.Range("J55"), Link:= False

This will paste whatever was in the clipboard onto Sheet1, aligned to cell J55. If the clipboard had an image, that image will be pasted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM