Word VBA:删除段落标记

时间:2018-08-06 15:27:08

标签: vba ms-word word-vba paragraph-marker

我有一些代码可以根据选择自动检测某些文本并将其放在用户表单上。

我面临的问题是删除结尾的段落标记。 (请参见下图):

enter image description here

我尝试了以下和其他变体,但无法删除结尾的段落标记:

Dim theText As String
theText = Replace(Selection, "^p", "") 

最后,我知道我可以使用Left(Selection,Len(Selection)-1),但是如果段落标记不存在,这将失败。

2 个答案:

答案 0 :(得分:0)

要获取Word中的段落,请使用以下2个选项之一(第一个选项适用于OP):

  • theText = Replace(Selection, ChrW$(13), "")

  • theText = Replace(Selection, ChrW$(244), "")

第二次贷记Remove paragraph mark from string

答案 1 :(得分:0)

如上面的注释中所述,这是解决方案:

Dim theText As String
theText = Replace(Selection, Chr(13), "")