Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Macro to add quote marks to unquoted bold words e.g. definitions in legal document Word 2010

    Hi, I am new to WindowsSecrets and need some help with a macro I'm trying to design. I work in a law firm and recently our house style has changed. In our legal documents definitions are set out at clause 1 in table format, first column being the name of the definition which are set out in bold Arial 10pt font without quote marks. Our new house style has now introduced quote marks. I have 1000s of documents to update in the Document Production Unit and wondered if there was a macro out there that could search for words in bold and insert quotes around the word(s). It needs to work within a table as well. At the moment my macro only puts quotes around the definition when I highlight the whole definition which is not want I want it to do, I want it to search for all bold words within a document and insert quotes around those bold words. Can anyone help me please - the following is what I have so far:
    Sub SC_AddQuotes()
    Dim sBegQ As String
    Dim sEndQ As String
    If Options.AutoFormatAsYouTypeReplaceQuotes Then
    sBegQ = Chr(147)
    sEndQ = Chr(148)
    Else
    sBegQ = Chr(34)
    sEndQ = Chr(34)
    End If
    Selection.InsertBefore sBegQ
    Selection.InsertAfter sEndQ

    End Sub

  2. #2
    Star Lounger
    Join Date
    Jul 2013
    Location
    Murphy, NC
    Posts
    66
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Hi Lady-Laughsalot,
    If a document has been impeccably formatted (e.g., no bold phrase has a leading bold space or trailing bold space), a macro having the following logical structure might work.

    # Start
    Go to top of document
    Search down for bold character
    Repeat until Not Found
    Insert quotation mark just before character
    Search down for non-bold character
    Search up for bold character
    Insert quotation mark just after character
    Search down for bold character
    End Repeat
    # End

    If two or more "consecutive" table cells might be bold, the above logic might fail to insert the "intermediate" quotation marks, in which case you might then run a macro that's something like the following.

    # Start
    For all tables
    For all cells
    If the first character in the cell isn't a quotation mark
    Then insert a quotation mark before the character
    If the last character in the cell isn't a quotation mark
    Then insert a quotation mark after the character
    End for
    End for
    # End

    Hope this helps,
    Dave
    Last edited by DavidHLevin; 2015-08-06 at 14:10.

  3. The Following User Says Thank You to DavidHLevin For This Useful Post:

    Lady-Laughsalot (2015-08-07)

  4. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim strFnd As String, i As Long
    With ActiveDocument
      For i = 2 To .Tables(1).Rows.Count
        With .Tables(1).Cell(i, 1).Range
          strFnd = Left(.Text, Len(.Text) - 2)
        End With
        With .Content.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Format = True
          .Font.Bold = True
          .Text = strFnd
          .Replacement.Text = Chr(34) & strFnd & Chr(34)
          .MatchWholeWord = True
          .MatchWildcards = False
          .MatchCase = True
          .Execute Replace:=wdReplaceAll
        End With
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    The above macro looks for all bold words in the first column of the first table in the document, starting from row 2 in the table, and encloses them in quotes.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. The Following User Says Thank You to macropod For This Useful Post:

    Lady-Laughsalot (2015-08-07)

  6. #4
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thank you so much for this macro, it is incredible and works a treat. Is there perhaps a way I can modify it to include definitions with a square bracket to the left of it, usually in a text form field.

    Column 1: Column 2

    [Appointment Letter text]

    Regards
    Shelley
    Attached Images Attached Images

  7. #5
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Thanks Dave for responding to my post, had trouble writing the macro for it but Macropod's works a treat.
    Regards
    Shelley

  8. #6
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Your image doesn't depict anything to do with formfields. All you have is text in one column with a preceding [ and in another column with a following ]. All that can be is text, since a formfield cannot span multiple table cells.

    Furthermore, you image also depicts cells containing expressions enclosed with double quotes. If you run the macro on such a table, you risk ending up with more double-quotes around your text - or text lacking the double quotes in the body of the document not being found. You do need to be careful about what you're doing with the macro; otherwise you'll end up with a mess.

    For text enclosed in [ ], you could change:
    strFnd = Left(.Text, Len(.Text) - 2)
    to:
    strFnd = Mid(.Text, 2, Len(.Text) - 4)
    However, that really isn't going to work when you have mixed text formats in the table (some cells with double quotes, some cells with no quotes, some cells with [ or ] but not both, etc.)
    Last edited by macropod; 2015-08-07 at 09:37.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. The Following User Says Thank You to macropod For This Useful Post:

    Lady-Laughsalot (2015-08-07)

  10. #7
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Hi Paul, thanks for getting back to me so quickly - unfortunately changing that bit of the code didn't work. I have taken out the form field square bracket and inserted a non field square bracket and when running the macro it did this: "[Appointment Letter". It must not like text form field the square bracket was in. Thanks for your help, very much appreciated.
    Regards
    Shelley

  11. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Your references to a "form field square bracket" are confusing. As indicated in the update to my previous post, whatever was depicted in your screenshot cannot have been part of a formfield. Indeed, if it were, you probably couldn't have used the macro, since it wouldn't run in a document with forms protection (which is what you need to work with formfields).
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #9
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts
    In legal documents when inserting form fields I have the command on my quick access toolbar (ab - Text Form Field), insert the blank field, double click and insert square bracket in the Default Text box so I can quickly F11 through a precedent document to delete when amending. The screenshot I attached was taken after I'd run your macro so that is why some quote marks were present, it was just a shot to show you where it didn't pick up. I can live with this happening as the macro still saves me heaps of time and I always check the doc before sending back to my boss. Thank you so much for your help, very much appreciated. Regards Shelley

  13. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    I can't see what inserting "[" achieves in terms of what you're doing, but you might try:
    strFnd = Replace(Left(.Text, Len(.Text) - 2), "[","")
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. The Following User Says Thank You to macropod For This Useful Post:

    Lady-Laughsalot (2015-08-10)

  15. #11
    Star Lounger
    Join Date
    Aug 2015
    Posts
    98
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Hi Paul, logged on to work this morning and tried your suggestion and I am absolutely thrilled to say it works. Thank you so so much. Regards Shelley

Posting Permissions

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