这是我的 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
现在我的文档中可能还有其他几条虚线,它们可能并不总是包含完全相同数量的点。
感谢您的阅读。