Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loop through Word document (Word 2000 SR-1)

    I want to search for text that continually occurs throughout a document and create a hyperlink with that text.
    I can find the first instance of that text OK, I can create a hyperlink using VB OK, but how can I loop through the open Word document?

    I tried using
    Do While Not EOF
    but when I do I get an error message: 'Compile error. Argument not optional'
    Thanks for your help.

  2. #2
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop through Word document (Word 2000 SR-1)

    To explain a bit further. Each document contains several (different) filenames in curly brackets. I want my VB to select the first set of brackets and hyperlink it to the filename contained within the curly brackets. Then move on to the next set and so on until it reaches the end of the document.
    I can do the hyperlink, and get the filename without the curly brackets OK, but can't seem to get the loop through the document to work.
    Any help is appreciated! Thanks again.

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Brussels, Brussel, Belgium
    Posts
    159
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop through Word document (Word 2000 SR-1)

    hi Ted,

    try recording and modifying a find operation. look at the code that is being generated and then press f1 on the keywords to display online help. in particular, have a look at the execute method in online help.
    if the items to be hyperlinked each start nicely on a separate paragraph, you could loop that collection to transform them into hyperlinks.

    when you feel you got stuck, post back with the code you have.

    greetings, pieter.

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop through Word document (Word 2000 SR-1)

    Hi Ted,

    In VBA, loops that run "until the end-of-file" is reached aren't usually used.
    EOF(filenumber) is a function that's only used for input (reading binary files or random access files from some data carrier.

    Much more commonly, you do your stuff "for every object in some collection", or, in your case, "as long as something is found".

    Try a loop along the lines of
    <pre>With Selection.Find
    ' search criteria here
    Do While .Execute
    ' modify search result here
    Loop
    End With</pre>

    ... or look at some sample code from the help files or search engine that contains "While .Found".

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop through Word document (Word 2000 SR-1)

    Thanks Klaus, that method worked just great.

    Many thanks to all.

Posting Permissions

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