Sub 空白单元格填充()
Dim doc As Document
Dim tbl As Table
Dim cell As cell
Dim para As Paragraph
Dim rng As Range
Set doc = ActiveDocument
' 遍历文档中的所有表格
For Each tbl In doc.Tables
' 遍历表格中的所有单元格
For Each cell In tbl.Range.Cells
' 遍历单元格中的每个段落
For Each para In cell.Range.Paragraphs
' 创建范围以便于检查和替换文本
Set rng = para.Range
rng.MoveEnd wdCharacter, -1 ' 删除段落末尾的换行符
' 检查段落的文本是否为空、为 "-" 或只包含换行符
If Trim(rng.Text) = vbCr Or Trim(rng.Text) = "-" Or Trim(rng.Text) = "" Then
' 将段落的内容替换为 "--"
rng.Text = "--"
End If
Next para
Next cell
Next tbl
End Sub
Word空白单元格填充——宏脚本
最新推荐文章于 2024-08-20 22:04:42 发布