Link to home
Start Free TrialLog in
Avatar of Benno Savioli
Benno SavioliFlag for Germany

asked on

export EXCEL-charts programmatically in 'Picture'- format

I know the options to export a chart via VBA in GIF or JPG - but the quality of this often is not as good as when choosing [shift]+[edit] - [copy picture] - appearance/size =as shown on screen and pasting it.
I'm wondering if there is a way to export the chart into the same format (i guess it is wmf or emf) that EXCEL uses internally for the above described copy-paste mechanism

I was already looking wild around for hours but I didn't find a proper solution so far - I presume I have to go over the clipboard object with API-calls etc. - that's beyond my semi-professional/amateur status

Thanks for a good working proposal
Avatar of Berkson Wein
Berkson Wein
Flag of United States of America image

I'm pretty sure that Excel only supports exports to jpg, png and maybe tif, all raster graphics.  WMF/EMF are vector and are far superior in quality when resizing.
There's a program http://www.asap-utilities.com/about-asap-utilities.php that is supposed to be able to export to wmf, though i don't know if it's usable through VBA or not.
It appears to be free for non-commercial use.
Avatar of Benno Savioli

ASKER

Thanks for the hint - but what I'm actually looking for is really a way for programatically (VBA) exporting into a file-format that is like the one used within copy-paste - I don't want to use a third party tool but to have a code to save from the clipboard into the graphic-file. Copy to the clipboard I can do via standard VBA - so the second step: identifying in and storing from clipboard is the critical point

Best regards

Benno
Lets talk more.  
First what version of excel?
Second, I wrote some code to copy the picture, but what do you want to do next, save it to a file or paste it into excel or another office application?
Hi Weinberk

Currently I'm still with EXCEL 2000 but I'm preparing to move to 2007 - nonetheless I'd prefer to have a solution that is not related to the newest Office version alone but more general.
In meantime I found codes that refer to manipulate the ClipBoard via API, but they all demonstrate only GetText or SetText.

Copy the chart programmatically to ClipBoard I know how to do with on-board tools of VBA as it is directly supported (as is the direct paste too)

What I wish to have is
1. something like 'GetPicture' from the clipboard and
2. Save this to file as *.emf or *.wmf with a file-name and path specified by me

Hope this is suffciciently clear

Best regards

Benno

This VBA code will get you the image to the clipboard:
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:= xlPicture
This is in Excel 2003, but it should work equally well in 2000.
I still think that you're going to be hard pressed to find a built in solution that will save the clipboard to a wmf or emf file.
This post (old) http://groups.google.ca/group/microsoft.public.access.modulesdaovba/browse_thread/thread/674742b64c6e7d01/3e95e8f696986245?lnk=st&q=getclipboarddata(cf_bitmap)+visual+basic&rnum=2#3e95e8f696986245 has info on saving the clipboard to a bitmap.
Have you considered the possibility of printing to a postscript file?
Or how about using a picture object and pasting from the clipboard.  Something like this
first copy to the clipboard as I showed in the previous post
then

Dim TheImageData As DataObject
Set TheImageData = New DataObject
TheImageData.GetFromClipboard
 
That'll get the metafile into the data object. I don't know how to get the DataObject into the picture control.  If you can figure that out, maybe the SavePicture function can then be used?  That might only be gif,jpg, etc again though.  Worth a shot.
I have no objection as I didn't receive a solution matching my question - I made a workaround for myself that is ok for the direct context of use but not what I had in mind

Sorry for not closing myself the topic earlier  

best regards

Benno
So post your solution for others to find.
I no way to know you didn't get a solution or that my suggestions didn't help since you didn't reply.
ASKER CERTIFIED SOLUTION
Avatar of Benno Savioli
Benno Savioli
Flag of Germany 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