【发布时间】:2018-08-01 08:07:53
【问题描述】:
这是我的 word 文档中的文本示例: https://www.noelshack.com/2018-31-2-1533054408-word.png
我是 VBA 新手,我正在尝试编写一个宏来查找特定文本“”““合格货币”是指基础货币和此处指定的其他货币:“并替换以下两行(填充带有一些点,不一定在同一段落中)带有文本列表(例如:欧元,美元)。
到目前为止,我已经能够使用代码循环浏览文档,找到特定的文本并对其进行编辑:
Sub FindAndFormat()
Dim objWord As Object
Dim wdDoc As Object
Dim ParagraphRange As Object
Dim intParaCount
On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = objWord.Documents.Open("D:\Modele.docx")
objWord.Visible = True
Dim Paragraph As Word.Paragraph
For Each Paragraph In wdDoc.Paragraphs
Set ParagraphRange = Paragraph.Range
ParagraphRange.Find.Text = """Eligible Currency"" means the Base Currency and each other currency specified here:"
ParagraphRange.Find.Execute
If ParagraphRange.Find.Found Then
ParagraphRange.Text = """Eligible Currency"" means the Base Currency and each other currency specified here: Euro, Dollar"
End If
Next
End Sub
注意整行的样式是加粗和斜体。
https://www.noelshack.com/2018-31-2-1533055581-word2.png
我真正想要实现的是替换虚线:
https://www.noelshack.com/2018-31-2-1533055647-word3.png
现在我的文档中可能还有其他几条虚线,它们可能并不总是包含完全相同数量的点。
感谢您的阅读。
【问题讨论】:
-
请花点时间阅读help center 中关于在 Stack Overflow 上提问的网站指南。您不应使用任何外部链接 - 将图片直接添加到您的问题中。