Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2003
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code not working in 2010

    Hello,
    Can anyone help me adjust the following code; it is acting on my whole document and not just my selection?

    Code:
    Sub FixHyphens()
    '
    ' Macro1 Macro
    ' Macro recorded 5/16/2003 by xxxxxx
    '
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        With Selection.Find
            .Text = "-"
            .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
    End Sub
    Thanks for any help.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    It has taken a while for you to notice that it wasn't working {recorded 5/16/2003} Perhaps the issue is that you need to ensure that there is a selection (rather than just an Insertion Point).

    Does this version work any better? The only real difference is the .Wrap command
    Code:
    Sub FixHyphens()
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "-"
        .Replacement.Text = "^~"
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
      End With
    End Sub
    Last edited by Andrew Lockton; 2012-03-06 at 17:02.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Lounger
    Join Date
    Jul 2003
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Andrew - Your code works. The reference to 5/16/2003 is because when my company upgraded to 2010 just a few weeks ago, I just copied my macros from my old normal to the new one. I tested them all then but failed to notice that this one was working on the whole document. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •