Displaying clipboard contents (image) to a userform

adampease

New Member
Joined
Apr 17, 2003
Messages
31
I am looking to display a picture currently copied to the clipboard in an image object in a userform.

The picture in the clipboard get there in the following way :
Code:
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

Any ideas?

Thanks,
adam
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Private Sub CommandButton1_Click()
Const FName As String = "C:\TempChart.gif"
Dim pic_rng As Range
Dim ShTemp As Worksheet
Dim ChTemp As Chart
Dim PicTemp As Picture
Application.ScreenUpdating = False
Set pic_rng = Worksheets("Sheet1").Range("A1:B3")
Set ShTemp = Worksheets.Add
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChTemp.Paste
Set PicTemp = Selection
With ChTemp.Parent
.Width = PicTemp.Width + 8
.Height = PicTemp.Height + 8
End With
ChTemp.Export Filename:="C:\TempChart.gif", FilterName:="gif"
UserForm1.Image1.Picture = LoadPicture(FName)
Kill FName
Application.DisplayAlerts = False
ShTemp.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
[/code]

The code copies the picture to a new blank Chart, exports the Chart and uses the resultant GIF file as the source for the Image Control.
 
Upvote 0
Thanks for your reply Andrew.

Is there a way to avoid saving the image in the clipboard to a file or pasting it into a chart between the clipboard and the image object on the userform?

I fiddled around trying to get the image from the clipboard into a DataObject or general Object then trying to set the picture property of the image object on my userform to that object but no success. It may not be possible, or (far more likely), i am not using these objects properly.

Thanks,
adam
 
Upvote 0
adampease said:
Is there a way to avoid saving the image in the clipboard to a file or pasting it into a chart between the clipboard and the image object on the userform?

Thanks,
adam

You can manually paste from the clipboard into the Picture property, but I don't think you can do it in code. Help says:

"While designing a form, you can use the control's property page to assign a bitmap to the Picture property. While running a form, you must use the LoadPicture function to assign a bitmap to Picture."

That's why I suggested my workaround.
 
Upvote 0
How did the picture get on the clipboard in the first place? If that code line in your first post is the result of you selecting the picture by browsing through an Open dialog box and selecting the graphic file, this code would load that selected picture onto the Image control and bypass the Clipboard.

Private Sub CommandButton1_Click()
Dim MyImage As String
MyImage = Application.GetOpenFilename()
If MyImage <> "False" Then Image1.Picture = LoadPicture(MyImage)
Me.Repaint
End Sub
 
Upvote 0
"pic_rng" in the following is a range within excel :

Code:
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture

CopyPicture is descripbed in Excel's Help as :
"Copies the selected object to the Clipboard as a picture."

The selected object in this case is a range of cells.

What i've done so far is build a macro that will, essentially, take a picture of the selected range of cells and the user can then choose to save that picture as a jpeg or gif but also leave it on the clipboard to paste into other applications. I wanted to have an interface pop up after the user chooses the range of cells and on this interface would be a 'preview' of the image that could then be saved or left on the clipboard.

adam[/code]
 
Upvote 0
Stephen Bullen as a solution that works great;

http://www.oaltd.co.uk/Excel/SBXLPage.asp#VBA

look for "pastepicture.zip". The only problems I have had using it come when running windows through a shell (off of a non-windows system) and the shell cannot handle the clipboard properly , so an error forms when the function tries to call the clipboard (i.e., not really a problem with the code, just the situation to use it). If you are using this on a normal PC, then its exactly what you want I think and much faster than J Walkenbach's code (exporting the ".gif" file).
 
Upvote 0

Forum statistics

Threads
1,224,809
Messages
6,181,075
Members
453,020
Latest member
mattg2448

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top