This macro compresses all pictures in the active worksheet of Excel to email size pixel 96 (ppi).
Compress All Pictures In Excel Worksheet
Sub CompressAllPictures()
Dim wsh As Worksheet
Dim shp As Shape
'Set wsh = Worksheets("Sheet1") 'Specify a worksheet
Set wsh = ThisWorkbook.ActiveSheet 'or use active worksheet
Application.ScreenUpdating = False 'Disable Screen Updating to speed up macro
For Each shp In wsh.Shapes
shp.Select
SendKeys "%e", True 'E-mail(96ppi)
'SendKeys "%w", True 'Web(150ppi)
SendKeys "~", True
Application.CommandBars.ExecuteMso "PicturesCompress"
Next shp
Application.ScreenUpdating = True
End Sub
How to Use This Macro
Most VBA code should be placed in Standard Modules unless specified.
If you see a comment '------------------ Modules------------------
in the code header that means put the code in a Standard Module. For more information, learn this course: Where should I put the Excel VBA code?
The following steps teach you how to put VBA code into a Standard Module:
- Activate the Visual Basic Editor by pressing ALT + F11.
- Right-click the project/workbook name in the Project Window.
- Choose Insert -> Module.
- Type or paste the code in the newly created module. You will probably need to change the sheet name, the range address, and the save location.
- Click Run button on the Visual Basic Editor toolbar.
- For more information, learn this course: Programming with Excel VBA
how to modify the code to do the same thing for all the worksheet of the workbook?