Link to home
Start Free TrialLog in
Avatar of CheyenneSlim
CheyenneSlim

asked on

Save MSChart to a file

How can I save an MSChart graph to a file?  I have tried all manner of methods using the ClipBoard and the RichTextBox.  I need to send a copy of the graph in an email, either in the body or as an attachment.

When I try to capture the MSChart by calling EditCopy, in the program it always returns a number about 10 digits long.  It is a different number every time (sometimes negative) and has no relationship to the data in the graph.  Yet, when I pause the code after calling the EditCopy and launch Word, the behavior of the manual paste is correct

  Clipboard.Clear
  MSChart1.EditCopy
   

  For I = 1 To 100000
    DoEvents
    If Clipboard.GetFormat(8) = True Then
      Exit For
    End If
  Next
 
   
  Open fname For Output As #ff
  Print #ff, Clipboard.GetData(8)

The file contains this value: -804975683  

I am obviously missing something.  What its it?  
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or

Private Sub Command1_Click()
MSChart1.EditCopy
SavePicture Clipboard.GetData(vbCFMetafile), fname
End Sub
B ecause the graph is a picture, and the number you get is the handle of that picture.
To save it to a file, you can save ii as a BMP file the following way, as suggested from MSDN:

Private Sub Command1_Click()
MSChart1.EditCopy
SavePicture Clipboard.GetData, "c:\test1.bmp"
End Sub
Emoreau told it correctly before me...
...give him the points!
Avatar of CheyenneSlim
CheyenneSlim

ASKER

Thanks!