• Regular Expression Find and Replace (2003 SP1)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Regular Expression Find and Replace (2003 SP1)

    Author
    Topic
    #424099

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #973024

      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.

      • #973310

        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?

        • #973328

          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.

    • #973030

      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

      • #973311

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

    Viewing 1 reply thread
    Reply To: Regular Expression Find and Replace (2003 SP1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: