- Joined
- Jul 21, 2021
- Messages
- 3
- Reaction score
- 0
Hi,
I have a successful code that performs search and replacement of the entire document, with MSGBOX monitoring this activity, allowing me to progress step by step, skip or cancel.
(Very similar to the existing function in Word, CTRL + H command)
1. I want to improve the code so that if I did not have my reference for 3 seconds (for example) he will consider it as if I clicked OK.
2. I also want to convert this code so that it works on selected text and not on the whole document.
I know this can be done using the CTRL + H command. But, for reasons of language issues, I need a separate and custom code.
3. The MSGBOX appears in the center of the screen. Is there a way to get her to appear on the sidelines, etc.?
My Code:
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("AAA")
myRange.Select
MyAnswer = MsgBox("Replace " & myRange.Find.Text & "?", vbYesNoCancel)
If MyAnswer = vbYes Then Call Shva_Na
If MyAnswer = vbCancel Then Exit Sub
myRange.Start = myRange.Start + Len(myRange.Find.Text)
myRange.End = cached
Loop
End Sub
I have a successful code that performs search and replacement of the entire document, with MSGBOX monitoring this activity, allowing me to progress step by step, skip or cancel.
(Very similar to the existing function in Word, CTRL + H command)
1. I want to improve the code so that if I did not have my reference for 3 seconds (for example) he will consider it as if I clicked OK.
2. I also want to convert this code so that it works on selected text and not on the whole document.
I know this can be done using the CTRL + H command. But, for reasons of language issues, I need a separate and custom code.
3. The MSGBOX appears in the center of the screen. Is there a way to get her to appear on the sidelines, etc.?
My Code:
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("AAA")
myRange.Select
MyAnswer = MsgBox("Replace " & myRange.Find.Text & "?", vbYesNoCancel)
If MyAnswer = vbYes Then Call Shva_Na
If MyAnswer = vbCancel Then Exit Sub
myRange.Start = myRange.Start + Len(myRange.Find.Text)
myRange.End = cached
Loop
End Sub