Word Tips VBA Commands (Simplifying Batch Operations)

Insert image description here
Tools-Macros-Visual basic editor:
Insert image description here

Content with borders

Sub Add borders to all inline content()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
With pic
.Line.Weight=1'Line width
.Line.Style=msoLineSingle'Line style
.Line.ForeColor.RGB=RGB(0,0,0)'Line Color
End With
Next
End Sub

Add borders to pictures

Sub 只给图片加边框()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
If pic.Type=wdInlineShapePicture Then
pic.Line.Weight=1
pic.Line.Style=msoLineSingle
pic.Line.ForeColor.RGB =RGB(0,0,0)
End If
Next
End Sub

Modify picture size

Sub batch modify picture size()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
pic.LockAspectRatio=msoTrue'Lock aspect ratio
pic.Width=CentimetersToPoints(6)'Set width to 6 cm (1 inch = 2.54 cm)
Next pic
End Sub

Add page breaks to images

Sub 给图片加分页符()
Dim pic As InlineShape
For Each pic In ActiveDocument.InlineShapes
If pic.Type=wdInlineShapePicture Then
pic.Range.InsertBreak Type:=wdPageBreak
End If
Next pic
End Sub

Modify text font

Sub 修改正文字体()
Dim currPara As Paragraph
For Each currPara In ActiveDocument.Paragraphs
If currPara.OutlineLevel=wdOutlineLevelBodyText Then
currPara.Range.Font.Size=12
End If
Next
End Sub

Remove hyperlink

Sub Delete Hyperlink()
Dim oDoc As Document
Set oDoc = Word.ActiveDocument
Dim oHL As Hyperlink
With oDoc
'Delete in reverse order
For i = .Hyperlinks.Count To 1 Step -1
Set oHL = .Hyperlinks(i)
With oHL
'Delete all hyperlinks (remove hyperlink) End Sub End With Next i End With
oHL.Delete




Continuously updating

Guess you like

Origin blog.csdn.net/wtt2020/article/details/134376254