1.應用
word書寫程序有時候需要批量修改圖片大小使得格式統一化,對每個圖片進行修改費時費力,寫了一些小程式批量修改希望對需要經常寫word的人有幫助。
2.程式
2.1圖片大小調整
' Sub 圖片格式調整()
'
' 圖片格式調整 宏
Dim n '圖片個數
On Error Resume Next '忽略錯誤
For n = 1 To ActiveDocument.InlineShapes.Count 'InlineShapes型別圖片
ActiveDocument.InlineShapes(n).LockAspectRatio = msoFalse '不鎖定縱橫比,重要,不然會變形
ActiveDocument.InlineShapes(n).Height = 6.73 * 28.35 '設定圖片高度為 260px,1cm=28.35
ActiveDocument.InlineShapes(n).Width = 14.57 * 28.35 '設定圖片寬度 413px
ActiveDocument.InlineShapes(n).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '圖片居中
Next n
' For n = 1 To ActiveDocument.Shapes.Count 'Shapes型別圖片
'
' ActiveDocument.Shapes(n).Height = 400 '設定圖片高度為 400px
'
' ActiveDocument.Shapes(n).Width = 413 '設定圖片寬度 300px
'
' ActiveDocument.InlineShapes(n).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter '圖片居中
'
' Next n
End Sub給圖片增加框
2.2圖片添加黑色邊框
Sub 增加圖片邊框()
'' 增加圖片邊框 宏
Dim oInlineShape As InlineShape
Application.ScreenUpdating = False
For Each oInlineShape In ActiveDocument.InlineShapes
With oInlineShape.Borders
.OutsideLineStyle = wdLineStyleSingle
.OutsideColorIndex = wdColorAutomatic
.OutsideLineWidth = wdLineWidth050pt
End With
Next
Application.ScreenUpdating = True
End Sub
uj5u.com熱心網友回復:
在Word2003中開始記錄宏,手動完成所需功能,結束記錄宏,按Alt+F11鍵,查看剛才記錄的宏對應的VBA代碼。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/69949.html
標籤:VBA
下一篇:VB下載多個大的BMP檔案的問題
