将5号或6号字体改为10.5号字体(循环10次)
AI复制的文案问题调整
js
Sub Change5or6ptTo16pt_10Loops()
Dim rng As Range
Dim doc As Document
Dim found As Boolean
Dim i As Integer
Dim totalChanges As Long
Dim targetSizes As Variant
Dim size As Variant
Set doc = ActiveDocument
totalChanges = 0
targetSizes = Array(5, 6) ' 要查找的字体大小数组
' 外层循环10次
For i = 1 To 10
found = False
' 遍历所有目标字体大小(5号和6号)
For Each size In targetSizes
' 遍历整个文档
For Each rng In doc.StoryRanges
Do
' 查找指定大小的文本
With rng.Find
.ClearFormatting
.Font.Size = size
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Execute
End With
' 如果找到,则更改字体大小
If rng.Find.Found Then
found = True
totalChanges = totalChanges + 1
rng.Font.Size = 10.5
End If
Loop While rng.Find.Found
Next rng
Next size
Next i
' 显示结果
If totalChanges > 0 Then
MsgBox "已完成将所有5号和6号字体更改为16号字体。" & vbCrLf & _
"共执行10次循环,总更改次数: " & totalChanges, vbInformation
Else
MsgBox "文档中没有找到5号或6号字体的文本。", vbInformation
End If
End Sub