Thursday, May 27, 2010

How to Compress Pictures in Excel using VBA

How to Programatically Compress Pictures/Images in Excel using VBA

If you are trying to compress pictures, you will normally be doing using the following dialog:



Compress Pictures Excel Dialog



The same dialog can be automated using Excel VBA and SendKeys as shown below:


Sub Compress_PIX()

Dim octl As CommandBarControl

With Selection
    Set octl = Application.CommandBars.FindControl(ID:=6382)
    Application.SendKeys "%e~"
    Application.SendKeys "%a~"
     octl.Execute
End With

End Sub 

Supressing "Compressing Pictures May reduce the quality of your images.." dialog is also taken care by SendKeys

The code uses CommandBarControl to find the Command and then execute the dialog

See also: How to Increase / Decrease Size of Images in Word Document using VBA

2 comments:

  1. Anonymous10:48 AM

    how can i select 96dpi?

    ReplyDelete
    Replies
    1. How do you get to this dialog box ???

      Delete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.