下面没有使用Selection的代码。
Sub Format paragraph()
Dim wdDoc As Document
With wdDoc.Range.Find
.Font.Size = 12
.Text = "?"
.Execute
End With
End Sub当找到字体大小= 12的字符时,如何更改当前段落的格式?例如:
wdDoc.Paragraph(current).Font.Size = 14
wdDoc.Paragraph(current).Font.Color = wdBlue谢谢你的帮助。
发布于 2019-06-16 21:05:15
诀窍是使用特定的Range对象,该对象可用于访问其“父”段。当Find.Execute成功时,正在搜索的Range包含已找到的项(与选择跳转到找到的项相同)。例如:
Sub Format paragraph()
Dim rng as Range, para as Paragraph
Dim wdDoc As Document
Set wdDoc = ActiveDocument. 'Missing in code in question...
Set rng = wdDoc.Content 'Content returns the Range
With rng.Find
.Font.Size = 12
.Text = "?"
If .Execute = True Then
Set para = rng.Paragraphs(1)
para.Font.Size = 14
para.Font.Color = wdBlue
End If
End With
End Subhttps://stackoverflow.com/questions/56620403
复制相似问题