【VBA/word】批量替换字体大小

将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
相关推荐
寻星探路40 分钟前
Java EE初阶启程记13---JUC(java.util.concurrent) 的常见类
java·开发语言·java-ee
哲Zheᗜe༘1 小时前
了解学习Python编程之python基础
开发语言·python·学习
落日漫游2 小时前
数据结构笔试核心考点
java·开发语言·算法
寻找华年的锦瑟2 小时前
Qt-配置文件(INI/JSON/XML)
开发语言·qt
HY小海2 小时前
【C++】AVL树实现
开发语言·数据结构·c++
workflower2 小时前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程
Roc-xb2 小时前
ModuleNotFoundError: No module named ‘conda_token‘
开发语言·python·conda
人工干智能3 小时前
Python 开发中:`.ipynb`(Jupyter Notebook 文件)和 `.py`(Python 脚本文件)
开发语言·python·jupyter
Jay-juice3 小时前
QT信号与槽
开发语言·qt
fs哆哆3 小时前
在VB.NET中,有没有 ?.这个运算符
java·开发语言·.net