Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    405
    Thanks
    35
    Thanked 5 Times in 5 Posts

    Regular Expression Find and Replace (2003 SP1)

    I need to do a search and replace of a set of numbers running down the left side of my page. The regular expression ([0-9]{1,2}[.]) catches everything I need to change. Unfortunately, it catches other stuff too.

    In particular, my documents has tables, and I want the regular expression to capture only things in the left hand column of each table. How do I get it to exclude stuff in the other columns?

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

    Re: Regular Expression Find and Replace (2003 SP1)

    Find/Replace doesn't "know" whether text is in the first column of a table.

    You could write a macro that loops through the tables in the document, selects the first column of each table and performs the find/replace on the selection.

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expression Find and Replace (2003 SP1)

    I don't know if this will help, even if it works in 2003. If you hold down Alt while selecting with the left mouse button, you can select a rectangular "block" which is not constrained to the start and end of lines. You could perhaps select only the required table column and execute the search/ replace on the Selection only.

    Alan
    Attached Images Attached Images

  4. #4
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    405
    Thanks
    35
    Thanked 5 Times in 5 Posts

    Re: Regular Expression Find and Replace (2003 SP1)

    If I did this, how would I get the macro to jump from one table to the next?

    For example, I could record a series of tab keystrokes to move through the table, but how do I get Word to go from the last cell of one table to the first of the next?

  5. #5
    4 Star Lounger
    Join Date
    Jun 2003
    Location
    Utah, USA
    Posts
    405
    Thanks
    35
    Thanked 5 Times in 5 Posts

    Re: Regular Expression Find and Replace (2003 SP1)

    This didn't work - I think because I have several tables to change rather than one table.

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

    Re: Regular Expression Find and Replace (2003 SP1)

    You don't use Tabs etc., you loop through the tables:

    Dim tbl As Table
    Dim cel As Cell
    For Each tbl In ActiveDocument.Tables
    For Each cel In tbl.Columns(1).Cells
    cel.Range.Find.Execute FindText:="...", ReplaceWith:="...", Replace:=wdReplaceOne
    Next cel
    Next tbl

    You must substitute the correct find and replace text, of course.

Posting Permissions

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