Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sometimes I receive documents that have “mixed” regular single/double quotes with curly quotes and I would like to create a macro that would search for “regular single/double” quotes and change them all to “curly quotes”.

    I also would like for the macro to change “regular hyphens” to a “nonbreaking hyphens”; i.e., - to ^~, because I want the sets of numbers (e.g., 13-15) that end at the end of the line to stay together, it drives me crazy to see half the numbers on one line and the rest on the other.

    I can do it manually, you know, Find and Replace; however, a macro would be great. I have recorded the steps but when I play the macro the dialog box comes up and I have to accept the dialog box, which I do not want to do. I want it to go through the document automatically.

    Thank you in advance.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by vgarrim View Post
    I have recorded the steps but when I play the macro the dialog box comes up and I have to accept the dialog box, which I do not want to do. I want it to go through the document automatically.
    Can you post a document or template containing your existing code and some sample text to test on? I'm not sure why the dialog appears, but the code might require only a few changes. Faster than someone else rebuilding it from scratch.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    This untested aircode in which you firstly set the basic parameters and then in three lines set the find text, replacement text and do it. If your options are set to autocorrect straight quotes with curly quotes then you simply search and replace the same thing.
    Code:
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
          .Format = False
          .Wrap = wdFindContinue
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .Text = “'”
        .Replacement.Text = “'”
        .Execute Replace:=wdReplaceAll
        .Text = “”””
        .Replacement.Text = “”””
        .Execute Replace:=wdReplaceAll
        .Text = “-”
        .Replacement.Text = “–”
        .Execute Replace:=wdReplaceAll
      End With
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I decided to re-record the macro to see if maybe I had done something wrong. I guess I must have done something wrong. The macro below works exactly as I want. It works. No dialog box. Don't know what happened before.

    Again, thank you so very much for all of you who take the time to try to help.


    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "'"
    .Replacement.Text = "'"
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
    .Text = """"
    .Replacement.Text = """"
    .Forward = True
    .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
    .Text = "-"
    .Replacement.Text = "^~"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

Posting Permissions

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