我正在用Visual (我知道)编写一个宏来解析Microsoft中的文档。这就是我想要实现的工作流程:
Edit > Find > Find...
)。Edit > Find > Replace... > Replace
,但在执行替换之前使用确认对话框)。我可以用 method进行查找和替换
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", _
ReplaceWith:="hello", Replace:=wdReplaceAll
但是,我不知道如何在执行替换之前提示用户。
发布于 2015-04-19 15:03:18
您可以使用消息框提示,然后测试返回值并在此基础上执行替换:
Private Sub PromptForReplace()
Dim myRange As Range
Set myRange = ActiveDocument.Content
myRange.Find.ClearFormatting
myRange.Find.MatchWildcards = True
Dim cached As Long
cached = myRange.End
Do While myRange.Find.Execute("hi")
myRange.Select
If MsgBox("Replace " & myRange.Find.Text & "?", vbYesNo) = vbYes Then
myRange.Text = "hello"
End If
myRange.Start = myRange.Start + Len(myRange.Find.Text)
myRange.End = cached
Loop
End Sub
https://stackoverflow.com/questions/29736847
复制相似问题