Clipboard images to Bitmap files through VBA in Excel

E

Elliot

This is an 'older' question (in that I know it's been asked before, but I'm
not sure anyone has ever answered it). Specifically I'm looking for a
workbook example that allows a user to take whatever has most recently been
copied into the clipboard and save that as a BMP image (ie. with a .bmp
extension, not jpeg or gif or png formatted) using VBA.

Lebans has some older code posted on-line, but I can't get it to work. It
might be that I haven't added all the necessary references, but I am
including the OLE reference that he suggests - again no dice.

Please assist,
Thanks
 
E

Elliot

Doesn't seem to be working in Excel 2007 (ok in 2003, but I don't get any
result returned for oPic - Paste Picture function doesn't seem to be working
in 2007).
 
P

Peter T

I meant for you to extract the relavant APIs and code and adapt for your
needs.

Drag modPastePicture from PastePicture.xls into your project, add another
module with the following

' Save image in the clipboard (if any)
' requires modPastePicture from Stephen Bullen's PastePicture.xls
' to test press (Alt or Ctrl) PrtScn before running
Sub SaveClipboardBMP()
Dim vFile As Variant
Dim sFilter As String, lPicType As Long
Dim oPic As IPictureDisp

On Error Resume Next
Set oPic = PastePicture(xlBitmap)
On Error GoTo 0

If oPic Is Nothing Then
MsgBox "no image in clipboard"
Else
sFilter = "Windows Bitmap (*.bmp),*.bmp"
vFile = Application.GetSaveAsFilename( _
initialfilename:="", filefilter:=sFilter)
If vFile <> False Then
SavePicture oPic, vFile
End If
End If
End Sub

Regards,
Peter T
 
J

j

Hi Elliot

did you find a solution for this? I get similar issues when using Win API
Clipboard method GetClipboardData - there are no BMP types on the Windows
clipboard (enum=2) following Paste of any kind from VBA?

cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top