Vba 编辑文本时保留邮件合并字段
我正在写一个宏来清理Word中的表。它遍历表,如果给定的单元格包含邮件合并字段,则应删除单元格中的其余文本,并保持邮件合并字段不变。我认为我当前的解决方案不起作用,因为它将占位符标记作为文本写入,而不是保留占位符对象-文本看起来正确,但MM没有做任何事情。另外,这是在OSX上,所以我无法访问某些库,因此没有正则表达式。如何查找和保留合并字段对象Vba 编辑文本时保留邮件合并字段,vba,ms-word,Vba,Ms Word,我正在写一个宏来清理Word中的表。它遍历表,如果给定的单元格包含邮件合并字段,则应删除单元格中的其余文本,并保持邮件合并字段不变。我认为我当前的解决方案不起作用,因为它将占位符标记作为文本写入,而不是保留占位符对象-文本看起来正确,但MM没有做任何事情。另外,这是在OSX上,所以我无法访问某些库,因此没有正则表达式。如何查找和保留合并字段对象 Public Sub TableSweep() Dim oRow As row Dim oCell As Cell Dim cellText As S
Public Sub TableSweep()
Dim oRow As row
Dim oCell As Cell
Dim cellText As String
Dim startInd As Integer
Dim endInd As Integer
'ensure cursor is within table
Selection.Collapse Direction:=wdCollapseStart
If Not Selection.Information(wdWithInTable) Then
MsgBox "Can only run this within a table."
Exit Sub
End If
For Each oRow In Selection.Tables(1).Rows
For Each oCell In oRow.Cells
cellText = oCell.Range
startInd = InStr(cellText, "«")
endInd = InStr(cellText, "»")
If startInd > 0 And endInd > 0 And endInd > startInd Then
cellText = (Mid(cellText, startInd, endInd - startInd + 1))
oCell.Range = cellText
End If
Next oCell
Next oRow
End Sub
您是否可以使用
Range
对象的Text
属性来获取和设置文本,并使用Fields
属性(oCell.Range.Fields.Count>0
)要查看单元格中是否存在字段?是否可以使用范围
对象的文本
属性来获取和设置文本,并使用字段
属性(oCell.Range.fields.Count>0
)要查看单元格中是否存在字段?能否使用范围
对象的文本
属性来获取和设置文本,并使用字段
属性(oCell.Range.fields.Count>0
)查看单元格中是否存在字段?