Search code examples
vbareplacems-wordconfirmation

MS-Word Macro - replace - confirming after work


I am not an engineer, and I am not IT worker. But I am... a sport journalist.

I write many articles on the road. I use for this Google Voice. But we have one problem with polish language in Google Voice. It doesn't... convert punctuation marks.

I created The Macro in Microsoft Word. But it is not 100% to my satisfaction. I have problem with confirming changes after all of work.

After use my Macro, I need to push the button 'YES' after its work. MS-Word ask me: "MS-Word finished searching of selected text. Numbers of changes: 0/1/2 etc. Should I search the rest of the document?".

I have 11 replacements in Macro and every word I need push YES... 11 times (even when it replaces 0 times) :)

I attached my Macro, maybe someone from your community could help and modify my idea. Thanks a lot, best regards.

Sub GoogleVoice()
'
' GoogleVoice Makro
'
'
    Selection.WholeStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = " przecinek"
        .Replacement.Text = ","
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " kropka"
        .Replacement.Text = "."
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " dwukropek"
        .Replacement.Text = ":"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "myślnik"
        .Replacement.Text = "-"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " znak zapytania"
        .Replacement.Text = "?"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " wykrzyknik"
        .Replacement.Text = "!"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " cudzysłów"
        .Replacement.Text = """"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " zamknij nawias"
        .Replacement.Text = ")"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
      Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = "trzykropek"
        .Replacement.Text = "..."
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
        .Text = " nawias "
        .Replacement.Text = "("
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = " enter"
        .Replacement.Text = "^p"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Solution

  • The prompts are caused by wdFindAsk. Your code can also be greatly simplified. Try:

    Sub GoogleVoice()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Text = " przecinek"
      .Replacement.Text = ","
      .Execute Replace:=wdReplaceAll
      .Text = " kropka"
      .Replacement.Text = "."
      .Execute Replace:=wdReplaceAll
      .Text = " dwukropek"
      .Replacement.Text = ":"
      .Execute Replace:=wdReplaceAll
      .Text = "myslnik"
      .Replacement.Text = "-"
      .Execute Replace:=wdReplaceAll
      .Text = " znak zapytania"
      .Replacement.Text = "?"
      .Execute Replace:=wdReplaceAll
      .Text = " wykrzyknik"
      .Replacement.Text = "!"
      .Execute Replace:=wdReplaceAll
      .Text = " cudzysłów"
      .Replacement.Text = """"
      .Execute Replace:=wdReplaceAll
      .Text = " zamknij nawias"
      .Replacement.Text = ")"
      .Execute Replace:=wdReplaceAll
      .Text = "trzykropek"
      .Replacement.Text = "..."
      .Execute Replace:=wdReplaceAll
      .Text = " nawias "
      .Replacement.Text = "("
      .Execute Replace:=wdReplaceAll
      .Text = " enter"
      .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
    End Sub