• My Simple Word 2010 Macro Is Not Working

    Author
    Topic
    #2778331

    Hello.  I created the macro below in Word 2010.  My OS is Windows 7 Professional.  The macro is located in “normal.dotm”.  I assigned the keyboard shortcut “Alt-Z” to the macro.  When I type Alt-Z, nothing seems to happen. The macro is supposed to find (all instances of 1 or more spaces using wildcards), and replace (each instance with exactly 1 space).

    After I type Alt-Z, nothing seems to happen.  Then, if I type Ctl-H, the Search And Replace dialog box opens, and I see that the Find and Replace fields are populated by the text shown in the macro.  And if I click on “Replace All”, each instance of found text is replaced as I describe above.

    Some help please?

    [Start Of Macro]

    Sub F_GTE_1sp_R_1sp()

    ‘ F_GTE_1sp_R_1sp Macro


    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = “([.:])( @)([! ])”
    .Replacement.Text = “\1 \3”
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    End Sub

    [End Of Macro]

    Viewing 0 reply threads
    Author
    Replies
    • #2778522

      You don’t have an “execute”.
      And you have the clear statements outside the “with”.

      I would expect it to look like this (I don’t have Word so haven’t tested).

      Sub F_GTE_1sp_R_1sp()
      
      With Selection.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = “([.:])( @)([! ])”
      .Replacement.Text = “\1 \3”
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchAllWordForms = False
      .MatchSoundsLike = False
      .MatchWildcards = True
      .Execute Replace:=wdReplaceAll
      End With
      End Sub

      cheers, Paul

      1 user thanked author for this post.
    Viewing 0 reply threads
    Reply To: My Simple Word 2010 Macro Is Not Working

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: