【问题标题】:Word VBA: Remove Paragraph MarkerWord VBA:删除段落标记
【发布时间】:2021-03-08 16:39:47
【问题描述】:

我的代码可以根据选择自动检测某些文本并放置到用户表单上。

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

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

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

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

【问题讨论】:

  • 我猜Replace(Selection.Text, ChrW$(244), "") 应该可以工作 - stackoverflow.com/questions/26633904/…
  • 感谢@Vityata,但这个?instr(selection,ChrW$(244)) 返回 0 :(
  • ?instr(selection.Text,ChrW$(13))怎么样
  • 尝试在 Replace 函数中使用 Chr(13) 而不是 ^p。 ^p 仅适用于 Word 的内置查找,但不适用于 VBA 字符串函数。
  • 工作@Vityata!谢谢

标签: vba ms-word paragraph-marker


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    正如上面的 cmets 所提供的,这是解决方案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 2013-02-22
      相关资源
      最近更新 更多