Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Browsing and Multiple File F&R (Word 2003)

    I read with great interest the Browsing (VBA/Excel) topic because I, too, have been looking for code similar to what was suggested for Excel, but for Word 2003. Word doesn't seem to have a similar option (but then I've missed the obvious before <img src=/S/grin.gif border=0 alt=grin width=15 height=15>).

    What I'm trying to do is modify the code provided in Andrew Savikas' Word Hacks for Find/Replace in Multiple Files (Hack #31) in several ways to make it more useful for myself and my editors.

    My goal is to have a three-part macro. (1) Part 1 allows the editor to identify the files or the folder and keep that location information until this particular part of the macro is run again, which would automatically clear out the information, or until Word is exited, at which time the information would be removed from the macro. This identification needs to be via a dialog box, similar to the File Open box. In the hack the path is hardwired into the macro, requiring the macro to be edited each time it is used as follows:

    With Application.FileSearch
    .NewSearch
    .LookIn = "C:My Documents"
    .SearchSubFolders = False

    (2) Part 2 is the F&R in Multiple Files part, drawing the location information for the files/folder on which to run macro on from Part 1. Which raises the second problem with the hack -- the F&R text are also hardwired into the macro as follows:

    Set rng = doc.Range
    With rng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Dewey & Cheatem"
    .Replacement.Text = "Dewey, Cheatham & Howe"

    I need to create an interactive way for my editors to enter the Find text and the Replacement text so that this part of the macro can be used and reused repeatedly for different F&Rs.

    (3) Part 3: Not included in the hack, but something else that I am trying to include, is the creation a record of the text entered as the Find and as the Replacement in a separate Word document along with a corresponding list of the files (not the folder where the files were located when the F&R was run) on which the F&R was run in alphabetical order by the Find entry.

    Here's what I'm trying to accomplish: We usually work on book manuscripts that run 75 to 300 chapters (1 chapter to a file). The chapters rarely all arrive together, usually arrive out of sequence, and are written by different authors. Part of our job is to make usage consistent (for example, that an acronym's meaning is the same in each chapter, such as CT always means computerized tomography and not sometimes computed tomography). Part 1 of the macro would allow the editor to easily identify where the other chapters to be searched are located. Part 2 would allow her, using the CT example, to search for every instance of CT in the chapters conform each instance to computerized tomography. Part 3, by creating the separate document, would allow her to (a) make the same F&R on additional chapters as she was assigned them, ([img]/forums/images/smilies/cool.gif[/img] tell her on which chapters she already had done the particular search on, and provide a way for other editors who are working on the same project but different chapters to make the same F&R on their chapters.

    The most crucial parts are 1 and 2; part 3 would be nice but if I can get the macro to work with just parts 1 and 2, I would consider that a success. Any help on any one or more of the parts is appreciated. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Browsing and Multiple File F&R (Word 2003)

    1) You can use FileDialog to let the user select a folder - see <post#=538,061>post 538,061</post#> for example code.

    2) You can use InputBox to prompt the user for the Find what and Replace with texts:
    <code>
    Dim strFindText As String
    Dim strReplacementText As String
    strFindText = InputBox("Enter the text to find.")
    .Text = strFindText
    strReplacementText = InputBox("Enter the replacement text.")
    .Replacement.Text = strReplacementText
    </code>
    You could also use a UserForm.

    3) You can create a new document and write information to it:
    <code>
    Dim docInfo As Document
    Set docInfo = Documents.Add
    ...
    docInfo.Content.InsertAfter "Find text: " & strFindText
    docInfo.Content.InsertParagraphAfter
    docInfo.Content.InsertAfter "Replacement text: " & strReplacementText
    docInfo.Content.InsertParagraphAfter
    </code>
    In the loop through the documents, you can use similar code to write the name of the document to the info document.

  3. #3
    2 Star Lounger
    Join Date
    Sep 2005
    Location
    Poughkeepsie, New York, USA
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Browsing and Multiple File F&R (Word 2003)

    Thank you, Hans. I just looked at post 538,061 and see that it uses the FolderPicker. I had tried to write my macro using FolderPicker, but I had been unable to figure out how to get it to retain the selected folder name. I see that my error was in the If . . . End If statement. I appreciate your leading me to this code.

    I also thank you for the InputBox code. Again I had tried using the InputBox but I had it completely backwards, which is why I couldn't get it to work and why I assumed I was trodding down the wrong path.

    As for the third item, that I had no clue about, so thank you a third time.

    I much appreciate the help you have been giving me. I do learn each time and I always try to solve the problem before I ask for help on the forum. I hope someday to be able to return the favors by being in a position to offer help to others.

Posting Permissions

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