PDA

View Full Version : Displaying a graph on a form



Damann
05-25-2006, 11:24 AM
Need a little help if some one can..

I have a graph in sheet one.

i have an image control on a form.

now i want to display this graph on the form when the form is displayed.

the way i understand from various readings, in order to create a picture i have to copy graph to clipboard and somehow create a picture to display in the image control.

there got to be a way to to place the graph in my picture control i just cant figure it out.

the graph is getting its data from a different sheet ( dunno if that matters. )

any ideas ?
i have look at picturepaste by STEPHEN BULLEN but that did not work for me. i could not figure out how to use his code to put in to mine.

thanks

mdmackillop
05-25-2006, 11:35 AM
Have a look at this
http://www.vbaexpress.com/forum/showthread.php?t=7760

Damann
05-25-2006, 12:30 PM
thats kinda what i was trying to avoid.

here is what i am looking at

Sub displaygraphinform()
Sheets("Diameter or weight").Activate ' Chart is in this sheet
ActiveChart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture

'Set Image2.Picture = CopyPicture(xlPicture) image control to display in
End Sub

problem with above is copypicture is not an object.

my problem here is i do not know how to get it off the clipboard.
i would like to set image2= to what ever is on clipboard

is there a simular paste i could use to put the image in the image control.

MountainVogu
05-28-2006, 08:12 PM
Steven Bullens' code is pretty self explanatory really, he gives almost more comment with his code than he does code ! and is a great source of info as ever.

I suggest you use the break and step though features of the VBE which would surely have explained what his code does.

anyway

dump this in the initiate section of your form

Private Sub UserForm_Initialize()
Sheet1.ChartObjects(1).Copy 'The chart you what to copy
Set image1.Picture = PastePicture() 'image1 is the name of the image control
End Sub


paste Stevens modPastePicture module from his example into your modules section and away you go.

Of course this removes the nice fuctionality of the best format to use.

COULD NOT REALLY BE SIMPLIER

Dave
05-29-2006, 05:42 AM
Perhaps a bit different approach. Export the chart to a GIF file then load the picture to your image control on the userform. HTH Dave

Fname = ThisWorkbook.Path & "\" & "ChartName.gif"
ActiveChart.Export Filename:=Fname, FilterName:="GIF"
Userform1.Image1.Picture = _
LoadPicture(ThisWorkbook.Path & "\" & "ChartName.gif")

MountainVogu
05-29-2006, 02:23 PM
Dave, I get the drift from the previous post Damann was trying to avoid file creation. But can't say that for certain.