打开word,输入alt+f11
下个文档想要使用的时候,只需alt+f11找到normal的模块1运行
如果只需要所有图片居中,将代码with
到endwith
删除即可;同理,只需要边框将居中对齐那行代码删去即可只加边框
以下是AddBordersAndCenterImages的代码:
Sub AddBordersAndCenterImages()
Dim i As Long
Dim shape As InlineShape
' 遍历文档中的所有内嵌形状
For Each shape In ActiveDocument.InlineShapes
' 检查形状是否为图片
If shape.Type = wdInlineShapePicture Or shape.Type = wdInlineShapeLinkedPicture Then
' 给图片添加边框
With shape
.Borders.Enable = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleSingle
.Borders(wdBorderLeft).Color = wdColorAutomatic
.Borders(wdBorderRight).LineStyle = wdLineStyleSingle
.Borders(wdBorderRight).Color = wdColorAutomatic
.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
.Borders(wdBorderTop).Color = wdColorAutomatic
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).Color = wdColorAutomatic
End With
' 将图片居中对齐
shape.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End If
Next shape
End Sub
默认加0.75磅黑框
Enjoy~