+ Reply to Thread
Results 1 to 6 of 6

How to process a word document line by line looking for "tags"

  1. #1
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    How to process a word document line by line looking for "tags"

    Hello,

    Hopefully I am in the right place, seems strange to have word macro issues in an excel help forum If I am in wrong place I would appreciate some redirection tot e correct place.

    I have a reasonable knowledge of Excel macros and the VBA needed to do "complex stuff" but have very little experience with macros in Word (2010).

    My problem overview is that I need to process (parse) a document looking for predefined "tags" and then process the tag basically to add an entry into an Index of "tags" in a new section at the end of the document.

    I can understand the steps I need to do but have no clue as to how to do it in Word (in excel I would have a "better than fighting chance" but alas not in Word)

    If someone can point me to threads that can assist me that would also be very much appreciated

    Cheers

    Jmac1947

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to process a word document line by line looking for "tags"

    What kind of Indexing are you using? Word's Index tools allow you to tag all entries of the same kind for inclusion in an Index without the need for code.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: How to process a word document line by line looking for "tags"

    Hello Paul,

    Thanks for the response. I suspect that my relatively careless use of english has caused a potential confusion. I am really not looking to simply index the document (although you have prompted me to look at the word feature that I don't think I have ever used before).

    I am looking at parsing a word document line by line.

    In essence I ignore all lines until I get to a tag that tells me I am starting a new group. I process all lines until I get to the next new group marker. In between the two "new group markers" there are a variable number of of "sub event tags" that I need to record as well.

    I don't actually have a soft copy of the document to process as yet, this is me trying to see how it might be possible to achieve my goal.

    The context is processing a transcript of proceedings. A new witness is called (aka a new group tag) and then a number of events can take place such as examined by "A", cross examined by "B", questioned by Judge, recalled, re-examined etc. until the witness "withdraws" and a new witness is called (aka a new group tag is found)

    There are a couple of complexities to worry about but basically that is the process. As I find the tags I need to write them, along with appropriate page number, into what is effectively a summary of the tags which can be called "an index".

    What I don't have any clue about is how to process a word document line by line, how I know the last line, how I know the page number etc.

    As I alluded to in OP, I have a pretty fair grasp of VBA in the excel worksheet processing mode but no idea about word

    John

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to process a word document line by line looking for "tags"

    Have a think about this:
    1. For each Witness, apply a Heading Style to whatever paragraph represents their calling, for example:
    Witness Blogs Sworn
    From then on, one might reasonably suppose all testimony is from that witness until you get to either the next witness or, say, a paragraph with, say:
    Judge's Summary
    With Word's Heading 1 Style applied to each of these.
    2. Similarly for the 'examined by', 'cross-examined by', 'questioned by Judge', etc, you could apply the Heading 2 Style.
    3. Inserting a Table of Contents at either end of the document. This will create a linked list to each of those headings - with page #s if you want, with the items for Heading 2 listed under the corresponding Heading 1 entries.

    Again, no code required.
    Last edited by macropod; 05-18-2014 at 02:02 AM.

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: How to process a word document line by line looking for "tags"

    Thanks Paul,

    That is about exactly the process I was thinking about and trying to describe.

    Unfortunately the end user is fixed on a simple "one touch macro" resolution to the issue, mostly I suspect because the group is looking to reduce the actual work involved in doing your suggestion.

    I do like your thinking however and will see what I can "conjure up" as a demo for the user, maybe they will change their "hard and fast" requirements.

    I do appreciate your help.

    I see you are reasonably prolific in this part of the VBA forum. Can you possibly point me to a simple example of how you would process a word document in the manner I am used to in excel (fine the last row, process each row from x to last row "doing stuff".

    A reasonable alternative that doesn't mean more work for you is "is there a word macros for dummies" type of background material available


    John

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: How to process a word document line by line looking for "tags"

    If the 'headings' are consistent (eg 'Witness Smith Sworn', 'Witness Blogs Sworn', 'Witness examined by Jones', etc.), it's quite feasible to use Find/Replace for applying the Heading Styles. That could even be incorporated into a macro (even via the macro recorder) that adds the table of contents. A hand-crafted macro would undoubtedly be better, but a recorded one, if done carefully, would be sufficient. For example:
    Please Login or Register  to view this content.
    The above macro will apply the Heading 1 Style to paragraphs consisting of:
    • Opening Address
    • Witness (name) called
    • Judge's Summary or Judge (name)'s Summary, etc
    and will apply the Heading 2 Style to paragraphs consisting of:
    • Examined by (name)
    • Cross-Examined by (name)
    • Questioned by Judge, or Questioned by Judge (name)
    It then adds a table of contents that will 'index' these at the start of the document.
    Last edited by macropod; 05-18-2014 at 04:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 01-29-2014, 08:10 PM
  2. [SOLVED] Problem creating Line Chart from columns "date" and "money"
    By brosef in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 11-05-2012, 09:01 AM
  3. [SOLVED] "carriage return" VS "line feed" and a little *BOLD*
    By jvanroekel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-03-2012, 11:48 AM
  4. How to change "From" & to have a dynamic "Subject" line in Excel Mailing
    By andy_iyeng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2012, 03:04 AM
  5. Replies: 4
    Last Post: 02-03-2008, 05:11 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1