【VBA/word】批量替换字体大小
将5号或6号字体改为10.5号字体(循环10次)
AI复制的文案问题调整
Sub Change5or6ptTo16pt_10Loops()Dim rng As RangeDim doc As DocumentDim found As BooleanDim i As IntegerDim totalChanges As LongDim targetSizes As VariantDim size As VariantSet doc = ActiveDocumenttotalChanges = 0targetSizes = Array(5, 6) ' 要查找的字体大小数组' 外层循环10次For i = 1 To 10found = False' 遍历所有目标字体大小(5号和6号)For Each size In targetSizes' 遍历整个文档For Each rng In doc.StoryRangesDo' 查找指定大小的文本With rng.Find.ClearFormatting.Font.Size = size.Text = "".Forward = True.Wrap = wdFindContinue.Format = True.ExecuteEnd With' 如果找到,则更改字体大小If rng.Find.Found Thenfound = TruetotalChanges = totalChanges + 1rng.Font.Size = 10.5End IfLoop While rng.Find.FoundNext rngNext sizeNext i' 显示结果If totalChanges > 0 ThenMsgBox "已完成将所有5号和6号字体更改为16号字体。" & vbCrLf & _"共执行10次循环,总更改次数: " & totalChanges, vbInformationElseMsgBox "文档中没有找到5号或6号字体的文本。", vbInformationEnd If
End Sub