Consulting

Results 1 to 2 of 2

Thread: help adding column titles / vba word find first line in column

  1. #1
    VBAX Newbie
    Joined
    Jan 2020
    Posts
    1
    Location

    help adding column titles / vba word find first line in column

    TLDR/the ask?:

    On a page setup for three columns, is there a way in word VBA to identify the line number where each column starts? (col 1 = line 1, col 2 = line 34, col 3 = line 70)

    The long version, w context:
    I am using mail merge's directory function to create a medical provider directory. I have already successfully created the document of the directory, but I have an issue adding one more feature. The page layout is three columns.The medical providers are grouped by specialty.The title for each specialty group only appears above the first entry for that group. I got that result by adding a new field in the source excel file, and only populating it for the first entry in each category.

    The issue I have is that I need to also repeat the category/specialty name at the top of each column on each page for reference, even when its not the first entry for that category.

    My thought was to "cheat" by adding the value on every entry, then using word vba to find every instance of the categories, see the line number, and if it is not on line 1 of that page, delete it, thereby leaving only the ones on top of each column.

    The issue I have is that I now learned that the line numbers ignore the three column set up. By this I mean that I would have expected the top line in the second column would be line 1, but it's actually 34, and column three starts on 70.

    The number of lines in each column is dynamic, because the entries have different number of fields (i.e. 2nd address on some, or fax on some, etc) and also the numbers of characters in some fields push the field on to two lines.

    My thinking is that if I can find a vba solution to find which line number starts each column on each page, I can then use that line number to decide whether or not to keep that field.

    I thought of using a three column header, but a) the header is already being used for a higher category value, and the values in the three column titles will change throughout the document.

    I know that my approach will also delete the legitimate category headers that exist on the first instance of category. If I can get that far, I think I will account for that by adding a leading text string to those, (XXX:CategoryName) so they do not get picked up on the first pass of find and replace, and the remove the leading string at then end

    Thanks so much for reading , sorry its so lengthy, any and all help or points in the right direction are very much appreciated!!!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,963
    Location
    You would do better to generate a table for each gouping, with a header row for the group specialty. That way, the specialty name can be made to automatically appear at the top of each new column. A mailmerge employing DATABASE fields can be used to generate the tables, which you could then modify by formatting the first rows as header rows.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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