打开 PowerPoint,按下 Alt + F11 打开 VBA 编辑器,点击菜单“插入-模块“,将以下代码粘贴进去:
Sub 图片批量最大化()
Dim sld As Slide
Dim shp As Shape
Dim slideWidth As Single
Dim slideHeight As Single
Dim ratio As Double
Dim picRatio As Double
slideWidth = ActivePresentation.PageSetup.slideWidth
slideHeight = ActivePresentation.PageSetup.slideHeight
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
' 只处理图片
If shp.Type = msoPicture Then
shp.LockAspectRatio = msoTrue
' 计算比例
picRatio = shp.Width / shp.Height
ratio = slideWidth / slideHeight
' 按比例放大以充满幻灯片
If picRatio > ratio Then
' 图片较宽,以高度为准
shp.Height = slideHeight
shp.Width = shp.Height * picRatio
Else
' 图片较高,以宽度为准
shp.Width = slideWidth
shp.Height = shp.Width / picRatio
End If
' 居中图片
shp.Left = (slideWidth - shp.Width) / 2
shp.Top = (slideHeight - shp.Height) / 2
End If
Next shp
Next sld
MsgBox "所有图片已最大化!", vbInformation
End Sub