Save Chart as EMF File for Import into Word

G

Guest

Hello,

I've successfully been exporting a series of dynamically generated charts
from Excel to GIF (I'm programming in VSTO) using code like:
Me.Application.ActiveChart.Export("C:\mygraph.gif","GIF")

I now need to export these same charts to EMF or WMF so that they can be
imported into Word and printed in high quality documents.

I've been trying the following, but with no luck:
Me.Application.ActiveChart.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlPicture, Excel.XlPictureAppearance.xlScreen)
Dim d As IDataObject = Clipboard.GetDataObject()
If (d.GetDataPresent(DataFormats.EnhancedMetafile)) Then
Dim pictBox1 As Image
pictBox1 = d.GetData(DataFormats.EnhancedMetafile)
pictBox1.Save("C:\mygraph.emf")
End If

Which dies with the error:
Object reference not set to an instance of an object.

The more I read, the more I feel like I'm nowhere close to the solution yet.
Can anyone point me in the right direction?

Any help appreciated.

Thanks
Todd
 

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