Word 文檔包含大量圖片需統一調整尺寸或按比例縮放?逐張手動調整極其耗時。使用 VBA 巨集腳本可一次處理文檔中所有圖片(含內嵌型 InlineShapes 與浮動型 Shapes),支援固定尺寸與比例縮放兩種模式,並可選擇性加入置中對齊。
Word 內部圖片尺寸單位為 點,1 cm ≈ 28.35 點。腳本中數值單位為點,請依需求換算(如 400 點 ≈ 14.1 cm)。
Sub SetPicFixedSize()
Dim n As Long
On Error Resume Next
' 處理內嵌型圖片
For n = 1 To ActiveDocument.InlineShapes.Count
ActiveDocument.InlineShapes(n).Height = 400 ' 高度 400 點
ActiveDocument.InlineShapes(n).Width = 300 ' 寬度 300 點
Next n
' 處理浮動型圖片/形狀
For n = 1 To ActiveDocument.Shapes.Count
ActiveDocument.Shapes(n).Height = 400
ActiveDocument.Shapes(n).Width = 300
Next n
End Sub


Sub SetPicScaleRatio()
Dim n As Long, picWidth As Single, picHeight As Single
On Error Resume Next
' 內嵌型圖片
For n = 1 To ActiveDocument.InlineShapes.Count
picHeight = ActiveDocument.InlineShapes(n).Height
picWidth = ActiveDocument.InlineShapes(n).Width
ActiveDocument.InlineShapes(n).Height = picHeight * 1.1 ' 放大 1.1 倍
ActiveDocument.InlineShapes(n).Width = picWidth * 1.1
Next n
' 浮動型圖片/形狀
For n = 1 To ActiveDocument.Shapes.Count
picHeight = ActiveDocument.Shapes(n).Height
picWidth = ActiveDocument.Shapes(n).Width
ActiveDocument.Shapes(n).Height = picHeight * 1.1
ActiveDocument.Shapes(n).Width = picWidth * 1.1
Next n
End Sub
在迴圈內加入:
ActiveDocument.InlineShapes(n).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
' 左對齊:wdAlignParagraphLeft
Shapes 集合包含:圖片、自選圖形、任意多邊形、OLE 物件、ActiveX 控制項等,不僅限圖片,執行前請確認範圍