【问题标题】:Remove text formatting and keep only text in a Numbered/ Word list删除文本格式并仅保留编号/单词列表中的文本
【发布时间】:2022-01-05 13:22:24
【问题描述】:

我有一个带有编号列表的 Word 文件,其中包含一些应用的文本格式。

我需要删除文本的格式并仅保留文本但保持列表编号不变。

我如何使用 VBA 通过一次一个项目遍历整个列表来实现这一点..请建议。

顺便说一句,我是使用 VBA 的新手,但对基础知识知之甚少。

这是我正在尝试的:

Public Sub Iterate_Paragraphs()
    Dim Paragraph As Word.Paragraph
    iParCount = ActiveDocument.Paragraphs.Count
    Dim sMypar As String

        For J = 1 To iParCount
            sMypar = ActiveDocument.Paragraphs(J).Range.Text
            sMypar.Copy
            sMypar.PasteSpecial datatype:=wdPasteText
            ActiveDocument.Paragraphs(J).Range.Text = sMypar
        Next J

End Sub

【问题讨论】:

  • Public Sub Iterate_Paragraphs() Dim Paragraph As Word.Paragraph iParCount = ActiveDocument.Paragraphs.Count Dim sMypar As String For J = 1 To iParCount sMypar = ActiveDocument.Paragraphs(J).Range.Text sMypar。复制 sMypar.PasteSpecial 数据类型:=wdPasteText ActiveDocument.Paragraphs(J).Range.Text = sMypar Next J End Sub
  • 嗨braX...这是我第一次上论坛...请原谅我的尴尬
  • sMyPar 是一个String,没有使用它的方法。除了提供代码之外,您还必须解释您有什么问题。 (有错误吗?或者它只是没有做你想做的事?)
  • 只是猜测,在循环中尝试ActiveDocument.Paragraphs(J).Range.Text = ActiveDocument.Paragraphs(J).Range.Text。它可能只是删除格式,但不确定是否保留列表编号。
  • 感谢吴先生的回复。我遇到了编译错误...循环内的限定符无效

标签: vba ms-word


【解决方案1】:

我会推荐你​​看这篇文章

https://wordribbon.tips.net/T010248_Converting_Automatic_Numbering_to_Manual_Numbering.html

其中显示以下代码


ActiveDocument.Range.ListFormat.ConvertNumbersToText

【讨论】:

  • 谢谢..会试试的
【解决方案2】:

要删除格式,除了ActiveDocument.Range.ListFormat.ConvertNumbersToTex,您还需要清除格式并将所有文本的样式更改为普通或正文样式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2016-01-19
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多