Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Macro to modify lines in table cells (2002)

    Hoping this is the correct forum?

    In each cell of a Word table with three main columns (each pair separated by a very thin column, as for labels!), I have a UK-style name-and-address in a number of lines, almost always four, five or six. Here is an example of the format:
    Joe Bloggs and Co Ltd
    Unit 3, Spratt Trading Estate
    Amoeba Road
    BLOGGSTOWN-SUPER-WOAD
    TO3 5JB

    I want to make some modifications to EACH name-and-address cell, as follows:
    a) Insert "The Managing Director" as a new line, in front of the (previous) first line
    [img]/forums/images/smilies/cool.gif[/img] if the postcode (final text line) is followed by a paragraph mark before the end-of-cell marker, remove the paragraph mark
    c) if the post town is not in CAPITALS, make it CAPITALS
    d) if there is only one blank space between the two halves of the post code, change this to two blanks.

    Looking at Creating a macro with no programming experience using the recorder I suspect I can do some of these requirements, those which don't require any IF tests. For example, I could force the second-last line to be CAPITALS even if it was already in this case.

    Since I've probably used only one Word macro in my life, and that many years ago, I wonder whether I'm being too ambitious here? I would like the macro to go through the whole file, missing out the thin vertical cells between each pair of columns, and stop neatly on the final cell which contains text (not necessarily the right-hand column, of course).

    Do I need a course in VBA?
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

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

    Re: Macro to modify lines in table cells (2002)

    John,

    I think this is a bit more than recording a macro can handle, in particular if the table could contain both manual line breaks and paragraph ends. The attached zip file contains a document with a macro FixTable that hopefully does what you want. I have assumed that the table is the first table in the document and that the text in the table doesn't contain special formatting; if it does, results may not be what you want.
    Attached Files Attached Files

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Macro to modify lines in table cells (2002)

    Hans

    Thanks for that - I will try to have a play omorrow!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

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

    Re: Macro to modify lines in table cells (2002)

    I have attached a modified version that takes empty cells into account. Additions are marked with comments starting with ***.
    Attached Files Attached Files

Posting Permissions

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