PDA

View Full Version : [SOLVED:] How to start Compress Pictures from VBA



RandomGerman
09-06-2018, 09:31 AM
Hi,

PowerPoint has this function Compress Pictures on the Pictures toolbar. Is it possble to active it from VBA, e.g., one of a few steps of a macro working on Pictures like this:


Sub PictureWork()
Dim shp As Shape

For Each shp In ActiveWindow.Selection.ShapeRange
If shp.Type <> msoPicture Then
MsgBox "Please select Pictures only"
Exit Sub
Else
shp.PictureFormat.ColorType = msoPicturesGrayscale
' shp. - - - activate the CompressPicture function?
End If
Next shp
End Sub


Would be great, to insert it, but I couldn't find it in the object library. Thank you for help.


By the way: Is something wrong with this Forum? I couldn't paste in my code, I had to type it, which wasn't fun either, because about every second letter gets lost while typing fast. :-(

John Wilson
09-06-2018, 10:22 AM
It's not in the object model as such but this clumsy workaround should work


Sub compressor()
Dim opic As Shape
Set opic = ActiveWindow.Selection.ShapeRange(1)
If opic.Type = msoPicture Then
CommandBars.ExecuteMso ("PicturesCompress")
SendKeys "%{e}" 'chooses Email
SendKeys "{ENTER}"
End If
If opic.Type = msoPlaceholder Then
If opic.PlaceholderFormat.ContainedType = msoPicture Then
CommandBars.ExecuteMso ("PicturesCompress")
SendKeys "%{e}"
SendKeys "{ENTER}"
End If
End If
End Sub

RandomGerman
09-07-2018, 08:21 AM
Wow! Great!

I assume, if I want the user to choose between the optional resolutions, I just have to delete the line



SendKeys "(ENTER)"

Then the input box appears.

Thank you and have a nice weekend!