数字化信息化智能化解决方案头像

批量实现word中所有表格头部文字全部加粗(测试可用)

Sub 加粗所有表格表头_兼容合并单元格()
    Dim tbl As Table
    Dim cell As Cell
    Dim headerRows As Integer
    Dim i As Long
    Dim cellRow As Integer
    
    ' 检查文档中是否有表格
    If ActiveDocument.Tables.Count = 0 Then
        MsgBox "当前文档中没有表格。", vbInformation
        Exit Sub
    End If
    
    ' ================= 设置区 =================
    headerRows = 1 ' 默认第一行为表头。如果表头有2行,改成2即可
    ' ==========================================
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    For Each tbl In ActiveDocument.Tables
        ' 遍历表格内的所有单元格(不使用 Rows,避免合并单元格报错)
        For Each cell In tbl.Range.Cells
            ' 获取当前单元格所在的真实行号
            cellRow = cell.RowIndex
            
            ' 判断当前单元格是否属于表头行范围
            If cellRow <= headerRows Then
                cell.Range.Font.Bold = True
            Else
                ' 如果当前行已经超过表头行数,直接跳出当前表格,去处理下一个表格(提高效率)
                Exit For
            End If
        Next cell
    Next tbl
    
    Applica

转载自 CSDN-专业IT技术社区

原文链接:https://blog.csdn.net/ducanwang/article/details/171044682

文章来源转载

评论

评论列表

微信小程序
QQ小程序

关于作者

点赞数:0
关注数:0
粉丝:0
文章:0
关注标签:0
加入于:--