Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Jan 2007
    Massachusetts, USA
    Thanked 0 Times in 0 Posts

    Find and Replace Macro for Figure Title Field Code (MS Word 2003)


    I am assembling a collection of word documents for publication, that were produced from several writers.
    In some instances I have found periods missing from the end of figure titles. I would like to create a Macro (if possible) that will:

    1. Open up a folder full of word documents.
    2. Place a period after the last letter in the figure title field.

    This will then ensure that the figure title has a period (at the end of the title) and save hours of time, since I have over 100 documents to review.

    Here are the field codes that are used in the documents I am reviewing:

    Figure { AUTONUMLGL * Arabic e }. Configuration File


    Figure { SEQ Figure * ARABIC }. Windows Explorer

    In that example, I would like to use a Macro to find and replace the titles, so that the end result is:

    Figure { AUTONUMLGL * Arabic e }. Configuration File.

    Figure { SEQ Figure * ARABIC }. Windows Explorer.

    The macro should search out each type of field code and then detect if a period is at the end of the sentence. If there is not period, it should insert a period.

    Thanks in advance for any suggestions to this problem.



  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Find and Replace Macro for Figure Title Field Code (MS Word 2003)

    Create a copy of the folder with the documents before trying the following code, and check the results carefully after running it.
    Sub ReplaceInFolder()
    ' Modify as needed, but keep the trailing backslash
    Const strFolder = "C:Test"
    Dim strFile As String
    Dim doc As Document
    Application.ScreenUpdating = False
    strFile = Dir(strFolder & "*.doc")
    Do While Not strFile = ""
    Set doc = Documents.Open(strFolder & strFile)
    ReplaceInDoc doc
    doc.Close SaveChanges:=True
    strFile = Dir
    Application.ScreenUpdating = True
    End Sub

    Sub ReplaceInDoc(doc As Document)
    ActiveWindow.View.ShowFieldCodes = True
    With doc.Content.Find
    .MatchWildcards = True
    .Execute FindText:="(Figure*AUTONUMLGL*<!t>[!.]<!/t>)(^13)", _
    ReplaceWith:="1.2", Replace:=wdReplaceAll
    .Execute FindText:="(Figure*SEQ Figure*<!t>[!.]<!/t>)(^13)", _
    ReplaceWith:="1.2", Replace:=wdReplaceAll
    End With
    ActiveWindow.View.ShowFieldCodes = False
    End Sub
    ReplaceInFolder is the macro to run. ReplaceInDoc is an auxiliary procedure used by ReplaceInFolder.

Posting Permissions

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