ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Charts and Charting in Excel (https://www.excelbanter.com/charts-charting-excel/)
-   -   Save Chart as EMF File for Import into Word (https://www.excelbanter.com/charts-charting-excel/117141-save-chart-emf-file-import-into-word.html)

Todd Garrison

Save Chart as EMF File for Import into Word
 
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.XlPic tureAppearance.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

Jon Peltier

Save Chart as EMF File for Import into Word
 
You could cut out the intermediate file, and simply copy the chart as a
picture in Excel and paste it into Word. I don't know the funky VSTO for it,
but in VBA it's pretty easy.

http://peltiertech.com/Excel/XL_PPT.html

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Todd Garrison" wrote in message
...
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.XlPic tureAppearance.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





All times are GMT +1. The time now is 02:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com