[VBA] Word圖片批次轉換大小

Una
2 min readSep 14, 2019

--

如果有一堆圖片在word裡面,要一起縮放一樣的大小。
一張一張調或是按F4重複上一步,真的很麻煩。
身為懶人當然希望一鍵處理,所以來寫VBA啦~~~

Step 1 檢視巨集

﹝檢視﹞ → ﹝巨集﹞ → ﹝檢視巨集﹞

Step 2 建立巨集

﹝輸入巨集名稱﹞ → ﹝輸入巨集描述﹞ → ﹝建立﹞

Step 3 輸入程式碼

﹝複製code﹞ → ﹝貼上code﹞

Step 4 修改程式碼

Sub BatchChangePicSize() 
Dim picWidth As Integer
Dim picHeight As Integer
Dim oIshp As InlineShape

picHeight = 12 * 28.32
picWidth = 24 * 28.32

For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.LockAspectRatio = msoFalse
.Height = picHeight
.Width = picWidth
End With
Next oIshp
End Sub
黃底數字 改成 您要的圖片大小

Width → 寬度

Height → 高度

﹝更改圖片長寬﹞ → ﹝存檔﹞, 存完檔就可以把VBA編輯器關掉。

Step 5 使用巨集

在word中,插入多張圖片後…

﹝檢視﹞ → ﹝巨集﹞ → ﹝檢視巨集﹞→﹝選擇巨集﹞→﹝執行﹞

code參考來源:PTT

--

--