View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default alternative to using the 'chart method' to exporting range as .jpg file

I guess I don't understand the problem with copying a range into an empty
chart, then exporting as PNG. The poor quality of a JPG produced this way is
irrelevant to the corresponding PNG. Any modern image viewer should read
PNGs with no trouble.

Also, any solution that relies on SendKeys will be prone to error.

- Jon
-------
Jon Peltier, Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/

Advanced Excel Conference - June 17-18 2009 - Charting and Programming
http://peltiertech.com/Training/2009...00906ACNJ.html
_______


"ARbitOUR" wrote in message
...

Hi All!

I've finally found the code I need to save the contents in MS Paint
(originally copied from Excel) in the required image format (.jpg =
lower quality than .png, but more compatible with various image
viewers). So here's the code to insert into the sub, after having
shelled MS Paint:




' Set Save As Parms
FileName = ThisWorkbook.Name

Application.Wait Now + TimeValue("00:00:01")
SendKeys ALT & "F", True ' File Menu
DoEvents
Application.Wait Now + TimeValue("00:00:01")
SendKeys "A", True ' Save As dialog
DoEvents
Application.Wait Now + TimeValue("00:00:01")
SendKeys Left(FileName, Len(FileName) - 1), True
DoEvents
SendKeys "{BACKSPACE 4}", True
DoEvents
SendKeys ".jpg", True ' Set image format
DoEvents
Application.Wait Now + TimeValue("00:00:02")
SendKeys "{TAB}", True ' Select 'save as
type' drop down menu
DoEvents
Application.Wait Now + TimeValue("00:00:01")
SendKeys "{DOWN 2}", True ' Select .jpg file
format
DoEvents
Application.Wait Now + TimeValue("00:00:01")
SendKeys "{ENTER}", True ' Activate
selection
DoEvents
Application.Wait Now + TimeValue("00:00:01")
SendKeys ALT & "S", True ' Save
DoEvents
Application.Wait Now + TimeValue("00:00:03")

'Close MS Paint
SendKeys ALT & "{F4}", True
DoEvents





I had to adapt the code for MS Paint for Windows XP to select the .jpg
format from the 'Save As Type' drop-down box. In MS Paint for Vista,
this part is not required since it automatically accepts the format as
specified by the extension.

Thanx to all of you for your valuable input!

ARbitOUR


--
ARbitOUR
------------------------------------------------------------------------
ARbitOUR's Profile:
http://www.thecodecage.com/forumz/member.php?userid=254
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=99833