奇怪,居然没代码。
Sub 插入前字符串()
Dim tbl As Table
Dim cell As cell
Dim para As Paragraph
' 遍历活动文档中的所有表格
For Each tbl In ActiveDocument.Tables
' 遍历表格中的每个单元格
For Each cell In tbl.Range.Cells
' 遍历单元格中的每个段落
For Each para In cell.Range.Paragraphs
' 在段落标记前插入指定字符 ...
Sub 插入前字符串()
Dim tbl As Table
Dim cell As cell
Dim para As Paragraph
' 遍历活动文档中的所有表格
For Each tbl In ActiveDocument.Tables
' 遍历表格中的每个单元格
For Each cell In tbl.Range.Cells
' 遍历单元格中的每个段落
For Each para In cell.Range.Paragraphs
' 在段落标记前插入指定字符串
para.Range.InsertBefore "前字符串 - "
Next para
Next cell
Next tbl
End Sub
Sub 插入后字符串()
Dim tbl As Table
Dim cell As cell
Dim para As Paragraph
Dim newText As String
' 设置新字符串
newText = " - 后字符串"
' 遍历活动文档中的所有表格
For Each tbl In ActiveDocument.Tables
' 遍历表格中的每个单元格
For Each cell In tbl.Range.Cells
' 遍历单元格中的每个段落
For Each para In cell.Range.Paragraphs
' 检查段落标记前是否为空内容
If para.Range.Characters(1).Text = "" Then
' 如果为空内容,直接在段落标记前插入新字符串
para.Range.InsertBefore newText
Else
' 如果不为空内容,在有内容的最后插入新字符串
para.Range.Characters(para.Range.Characters.Count).InsertAfter newText
End If
Next para
Next cell
Next tbl
End Sub