exporting Excel chart as an image

User avatar
stuck
Panoramic Lounger
Posts: 8182
Joined: 25 Jan 2010, 09:09
Location: retirement

exporting Excel chart as an image

Post by stuck »

Excel 2007 sp2

I have a problem with a PDF created from a Word 2007 doc that contains an Excel chart pasted special as 'Picture (Enhanced Metafile)' so a Googling I did go and found this code:
http://peltiertech.com/WordPress/enhanc ... procedure/
Worth a try, thinks I. However when I paste it into a Module and try to run it, Excel objects at the line:

Code: Select all

If Not FileExists(sChartName) Then Exit Do
Highlighting FileExists and saying, "Compile error: sub or function not defined"
:scratch:

Ken

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: exporting Excel chart as an image

Post by HansV »

The code uses some auxiliary routines from the File Name Functions page. You should copy the code from that page into the same module or into a separate module in the same workbook.
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8182
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: exporting Excel chart as an image

Post by stuck »

Ah! Thank you, obvious now that you point it out.

Also, there is an idiot version (i.e. an .xla in a zip file) at the very bottom of the page. The add-in works except the .png it created looked nothing like my chart!

Think I'll think again.

Ken

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: exporting Excel chart as an image

Post by HansV »

Another option is to save the workbook as a web page (*.htm, *.html). This will create a subfolder in the folder containing the .htm(l) file with a low and high quality version of the charts in the workbook.
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8182
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: exporting Excel chart as an image

Post by stuck »

So it is... that gave me a .gif file.

Initially it too looked nothing like my original chart but my default image file view is IrfanView. If I 'open with' and use Windows picture & fax viewer the graphic looks as I expected it. Perhaps this is an IrfanView 'issue' but I've not got time to experiment further right now.

Meanwhile, thanks again.

Ken

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: exporting Excel chart as an image

Post by HansV »

When I tried it I got two image files: a .gif (low quality) and a .png (high quality) of the same chart.

(I abandoned IrfanView some years ago. I didn't have a problem with its view capacity, but I found the interface rather clunky)
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8182
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: exporting Excel chart as an image

Post by stuck »

Hmm, just checked again, file save as web page (*.htm), only get a .gif, no .png

Ken
edited to add: You have to tick the .png option in the web options

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: exporting Excel chart as an image

Post by HansV »

Apparently that option was "on" for me by default, I'm sure I never looked at it on this PC, and yet I got both .gif and .png...
Best wishes,
Hans