VBA- Powerpoint:Auto Fix resolution for selected image- Export to fixed path -delete selected image




This macro optimizes the workflow by forcing a fixed resolution and exporting images to a preset path in one click.
1. Forces the selected object to 1280x1024
2.Automatically saves the image as pic1.png on the Desktop
3.Deletes the object after exporting to clear the workspace for the next screenshot.

Alt+F11 or go to Developer tab=>Visual Basic, create new module, copy and paste this code, adjust imgPath follow your device and run.

Sub SetSelectedImageResolution()  

 Dim shp As Shape

    Dim imgPath As String 

    imgPath = Environ("USERPROFILE") & "\Desktop\pic1.png" 'Change save folder and name here

    If ActiveWindow.Selection.Type = ppSelectionShapes Then

        Set shp = ActiveWindow.Selection.ShapeRange(1)

        shp.LockAspectRatio = msoTrue

        shp.Width = 1280

        shp.Height = 1024

        shp.Export imgPath, ppShapeFormatPNG 'save as PNG

       shp.Delete 'Delete the image to prepare for next image

    Else

        MsgBox "Select OBJECT", vbExclamation

    End If

End Sub


Nhận xét