Macro is copied from Grepper where I posted under the title "VBA compress all images in document to 150ppi"
Code: Select all
Sub MacroC_28_06_2022()
'Macro C compress all images in Document to 150ppi
'SOURCE: Grepper where I posted under the title "VBA compress all images in document to 150ppi"
'https://paypal.me/1ClickQAT?country.x=GB&locale.x=en_GB
Word.Application.ScreenUpdating = False 'doesnt stop CommandBars from flickering
'If Macro C is pressed in error with no file in Open Word App
If Word.Application.Documents.Count = 0 Then
Exit Sub
End If
Dim oIlS As inlineshape
If Word.ActiveDocument.InlineShapes.Count > 0 Then
'Select the first image so that the "Picture Format" Ribbon Menu appears
Word.ActiveDocument.InlineShapes(1).Select
'if can change status of CommandBar tick "Apply only to this picture" - loops not needed
VBA.SendKeys "%W{ENTER}", True 'save Macro c (lowercase) for 96ppi separate QAT & change %W for %E
'Opens the "Compress Pictures" Sub Menu on Picture Format
'A different version appear if the above Select 1st image line is switched off
Application.CommandBars.ExecuteMso ("PicturesCompress")
DoEvents '28/06/2022 Repeat SendKeys to stop NumLock toggle off or on if odd number of images
'deletd source
VBA.SendKeys "%W{ENTER}", True
Application.CommandBars.ExecuteMso ("PicturesCompress")
'deleted source
Dim PauseTime, Start, Finish, TotalTime
PauseTime = 0 'Add a delay if the CommandBars flicker is a problem
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
Else
End
End If
'Restarting a loop for the rest of the images in the Active Document
For i = 2 To Word.ActiveDocument.InlineShapes.Count
If Word.ActiveDocument.InlineShapes.Count > 1 Then
Word.ActiveDocument.InlineShapes(i).Select
VBA.SendKeys "%W{ENTER}", True 'save Macro c (lowercase) for 96ppi separate QAT & change %W for %E
Application.CommandBars.ExecuteMso ("PicturesCompress")
DoEvents
VBA.SendKeys "%W{ENTER}", True
Application.CommandBars.ExecuteMso ("PicturesCompress")
'Dim PauseTime, Start, Finish, TotalTime
PauseTime = 0 'Add a delay if the CommandBars flicker is a problem
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
TotalTime = Finish - Start
Else
End
End If
Next i
Word.Application.ScreenUpdating = True
End Sub