Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

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?  
0
CheyenneSlim
Asked:
CheyenneSlim
  • 2
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
try this:

Private Sub Command1_Click()
MSChart1.EditCopy
Set Picture1.Picture = Clipboard.GetData(vbCFMetafile)
SavePicture Picture1.Picture, fname
End Sub
0
 
Éric MoreauSenior .Net ConsultantCommented:
or

Private Sub Command1_Click()
MSChart1.EditCopy
SavePicture Clipboard.GetData(vbCFMetafile), fname
End Sub
0
 
CimperialiCommented:
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
0
 
CimperialiCommented:
Emoreau told it correctly before me...
...give him the points!
0
 
CheyenneSlimAuthor Commented:
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now