【发布时间】: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。它可能只是删除格式,但不确定是否保留列表编号。 -
感谢吴先生的回复。我遇到了编译错误...循环内的限定符无效