word使用宏命令批量按比例設置圖片大小


1,單擊文件

2.

 

3.如下圖,最后確定

 

 

 

 

 4.如圖

 

5.在彈出框中點擊創建,

 

 6.將宏命令copy到命令窗口中並點擊運行即可,也無需保存

注意,n需要替換為實際值:如15

 

 

 

 

 

 

代碼中單位厘米

(1)設置固定大小n厘米:

Sub resetImgSize()
Dim iShape As InlineShape
For Each iShape In ActiveDocument.InlineShapes
iShape.LockAspectRatio = msoTrue
iShape.Height = CentimetersToPoints(n)
iShape.Width = CentimetersToPoints(n)
Next
End Sub

(2)等比例縮放n倍

Sub resetImgSize()

Dim imgHeight

Dim imgWidth
Dim iShape As InlineShape
For Each iShape In ActiveDocument.InlineShapes
iShape.LockAspectRatio = msoTrue

imgHeight = iShape.Height

imgWidth = iShape.Width
iShape.Height = CentimetersToPoints(n * imgHeight )
iShape.Width = CentimetersToPoints(n * imgWidth)

Next
End Sub

(3)最大寬度n厘米等比例縮放:

Sub resetImgSize()

Dim imgHeight

Dim imgWidth
Dim iShape As InlineShape
For Each iShape In ActiveDocument.InlineShapes
iShape.LockAspectRatio = msoTrue

imgHeight = iShape.Height
imgWidth = iShape.Width

 

iShape.Height = CentimetersToPoints(n * imgHeight / imgWidth)
iShape.Width = CentimetersToPoints(n)
Next
End Sub

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM