unable to paste from clipboard

S

Sai

I am trying to copy a range as a picture from excel and paste that into a
picturebox on a form.

The code I am using to copy is
Globals.Profiles.Range("ProfileChart").CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlPicture)

to paste the chart into a picturebox I first tried
Me.PictureBox1.Image = Clipboard.GetImage

That did not work and then I tried
Me.PictureBox1.Image =
DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap, False),
Bitmap)

that did not work either.

I can paste the bitmap into any other application like word, excel or
outlook. When I query clipboard.containsimage I get false.

Please help !!!!!
 
R

Robin Hammond

Sai,

CopyPicture has always been a nightmare.

You need to export the chart as a graphic file then load it to the
picturebox. Here's an example in VB that should get you going.

Private Sub Form_Load()
Dim oXL As Excel.Application
Set oXL = GetObject(, "Excel.Application")
oXL.Sheets(1).ChartObjects(1).Chart.Export "c:\temp\chart.gif", "gif"
Set oXL = Nothing
Set Picture1.Picture = LoadPicture("c:\temp\chart.gif")
End Sub

If speed is critical, you could also have a look at Stephen Bullen's
pastepicture routine which I use a lot in my XspandXL add-in to speed up my
ChartBrowser routines.

It should be somewhere here: http://www.oaltd.co.uk/Excel/Default.htm

Robin Hammond
www.enhanceddatasystems.com
 

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