none
how to write VBA code of Word 2007 to insert a sign before the first underline and after the last underline? RRS feed

  • Question

  • title1;

    title2;

    _________________________________________________________

    content

    _________________________________________________________

    footnote1;

    footnote2;

    Thursday, October 3, 2013 2:23 PM

Answers

All replies

  • You don't provide enough information.

    Is this document being generated from scratch, or how are you expected to interact with it?


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, October 3, 2013 2:30 PM
    Moderator
  • this is a table shell. I want to insert a sign before the first underlline and the last underline to find titles and footnotes. thanks.

    Thursday, October 3, 2013 2:38 PM
  • I'm afraid I don't know what a "table shell" is, either.

    How are these underlines being inserted into the document? Is it being created from a template that contains them? If yes, insert a bookmark at this position in the template, so that it will also be in the newly created document. Then get the bookmark range and insert the "sign" there.


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, October 3, 2013 5:50 PM
    Moderator
  • table shell means that there is a file with 1000 pages(each page presents one unique table guideline). there are three parts for each table. one is titles, another content, another footnotes. these three parts are seperated by underline. per your advice, I need to insert bookmarks table by table. it there a dynamic way to insert a sign before the first underline and last underline to map the titles and footnotes for each table.?

    Thursday, October 3, 2013 6:32 PM
  • If you could please provide an answer to my first question in my previous reply? In order to "find" the "underlines" it's imperative to know what we're really dealing with. Whether these are "borders" or created by pressing the "_" key or by underline formatting applied to text and pressing the Space key....

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 4, 2013 3:16 PM
    Moderator
  • let me make it simple. please see below. there is each blank between title2; and first xxxxxxxxxx,  and between last xxxxxxxxx and footnote1; I plan to insert a sign between title2; and the first xxxxxxxxxx, and between the last xxxxxxxxx and footnote1;.

    title1;

    title2;

    xxxxxxxxxxx

    xxxxxxxxxxx

    xxxxxxxxxxx

    footnote1;

    footnote2;

    Friday, October 4, 2013 3:56 PM
  • You aren't answering my question. My question is: HOW ARE THESE LINES CREATED?

    If you read my last response carefully, you'll understand that there's more than one way to make a line in Word. In order for us to find these lines, and the spaces between, we need to know what kind of lines.

    There needs to be a UNIQUE WAY TO IDENTIFY the target points. You need to provide that information.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 4, 2013 4:02 PM
    Moderator
  • these lines are created from 'PROC REPORT' procedure via SAS ODS. they are not real lines from Word. that means these lines don't exist when I copied and pasted it from Word to Excel. there are only blanks in Excel instead.
    Friday, October 4, 2013 4:44 PM
  • these lines are created from 'PROC REPORT' procedure via SAS ODS. they are not real lines from Word. that means these lines don't exist when I copied and pasted it from Word to Excel. there are only blanks in Excel instead.

    Oh, dear. I am not familiar with the software you mention so have no idea what is creating these lines. Without some way to clearly identify the "target" areas, it is, of course, not possible to write code that does something.

    Would it be possible for you to share such a document over skydrive or something similar? I might be able to figure out what was used...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 4, 2013 5:11 PM
    Moderator
  • thanks for the questions and anwers. I really appreciate it. I think I can sovle the issue using other ways.
    Friday, October 4, 2013 5:15 PM
  • Assuming your 'lines' are just underscore characters as per your post, you can do this without VBA, using nothing more complicated than a wildcard Find/Replace, where:

    Find = [_]{1,}^13[!_]@[_]{1,}
    Replace = #^&$

    and the # and $ characters represent whatever it is you want to insert before & after the lines. If you want, you can record the Find/Replace as a macro.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, October 4, 2013 10:41 PM