How to compress all pictures in Workbook

tpthatsme

New Member
Joined
Jun 2, 2016
Messages
17
I am trying to cycle through all the sheets in my workbook and compress all pictures. I know there is a way to save my file with this option, but I would like to put this in the VBA so that it would be triggered each time the file is closed. I tried to search the interwebs and it gave me a starting point. The following script seems to work for the first sheet, but not the second, and every time it runs my number lock is changed. What do you think?
VBA Code:
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each ws In Application.ActiveWorkbook.Worksheets
        ws.Shapes.SelectAll
        SendKeys "%w", True
        SendKeys "~", True
    Application.CommandBars.ExecuteMso "PicturesCompress"
    Next
    Application.DisplayAlerts = True
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,632
Messages
6,173,472
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top