Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hyperlink Subaddress (VBA Word 2003 Win XP)

    I have just ported a piece of VBA code that I wrote for Word 2000 some time ago (2001) - helped by this board.
    It searches files or entire directories using MS Word's Find (SourceDoc.ActiveWindow.Selection.Find.Execute).

    It searches either

    <UL><LI>using a variety of masking techniques
    <LI>or Auto searches against an array of search words[/list]then creates a new results document for each document successfully searched.

    This results document contains a table with
    <UL><LI>a hyperlink to the location where the search term was found (.Hyperlinks.Add Selection.Range, Address:=SourceDoc.FullName, SubAddress:=SourceDoc.ActiveWindow.Selection.Sente nces(1)).
    <LI>the sentence or paragraph in which the search word was found,
    <LI>the page number[/list]for each instance of the search term or terms found.

    Having just ported it to 2003 without too many changes and without any major issues, I have identified a problem whereby the hyperlink in some of the entries keeps returning me to the front page of the source (searched) document rather than to the actual page/paragraph where the source was found.
    The test source is a very large document (a contract with some numbered and some unnumbered sections) where numbered sections that contain search items are hyperlinked to without any problem.

    I have also tried linking using .Hyperlinks.Add Selection.Range, Address:=SourceDoc.FullName, SubAddress:=SourceDoc.ActiveWindow.Selection.Infor mation(wdActiveEndPageNumber) but this can result in the hyperlink linking to the page number reference in the source documents TOC.

    I have previoulsy tried the PasteSpecial approach (see <post#=64735>post 64735</post#> ) with incomplete success.

    Ideally what I would like is to hyperlink to a specific paragraph consistently.
    Any pointers would be welcome <img src=/S/aussie.gif border=0 alt=aussie width=21 height=22> .

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    Could you zip up a little sample for those who have Word 2003 to try? It's not clear to me whether it's a problem with Word's handling of bookmarks, generally, or whether the bookmarks are changing (which also would be bad). But I have Word 2002, so I can't really test it myself.

  3. #3
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    <P ID="edit" class=small>(Edited by dansy on 04-Apr-05 11:15. )</P>Not really a zipped up sample yet but some more info.

    Background
    Multiple contracts, tender documents and attachments are searched using a VBA program for a large number of keywords (e.g. indemnity, waiver, subrogation etc). These terms are either auto generated as a result of the user selecting a radio button on a user form(resulting in 35 terms being searched for) , by the user selecting individual preset terms (resulting in 1 to 35 terms being searched for) or by the user selecting any number of terms that are manually entered and separated by a semicolon

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

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    To be able to distinguish between multiple occurrences of the same text in a source document, you'd need to create a bookmark for each occurrence. As a consequence, each search would modify the source document, and I don't think you want that.
    Your earlier method from 2001 using Paste Special had the same problem: if you paste special as a link, Word creates a bookmark in the source document and in the target document with a name such as OLE_LINK1, so the source document is modified. If you then close the source document without saving it, the link in the target document becomes invalid.

  5. #5
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    Hans,
    the real problem with PasteSpecial back in 2001 was that it behaved erratically.
    On occasion the pastespecial would fail indicating there was nothing in the clipboard - which was not the case.
    Converting it to a simple paste worked every time but obviously didn't create the link.

    My current code (continually evolving since 2001) works entirely as expected and is in daily use, however the hyperlink issue of this post is a real bugbear.
    Is there a mechanism whereby a relative address from the start of the document could be generated for use in the hyperlink in the scan results document?

    Thanks in advance.
    Dansy

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

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    Not that I know of. The subaddress for a hyperlink can either be specific text (in which case the link goes to the first occurrence of that text in the document), or the name of a bookmark. If you try to set the subaddress to a range, e.g.

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=myDoc.FullName, SubAddress:=myDoc.Range(1000,1010)

    the result will be a hyperlink to the text of Range(1000,1010), not to this specific range.

    You could store the full name of the document plus start and end of the range (1000 and 1010 in the above example) in the table. The user would click in a row, then click a custom toolbar button that opens the document and selects the range with the specified start and end. Less convenient than following a hyperlink...

  7. #7
    Lounger
    Join Date
    Aug 2001
    Location
    Perth,(aka middle of nowhere), Western Australia, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    Hans,
    I have been exploring the use of line numbers to do this.
    Couple of issues arise though
    1. A line number will eventually have the same problem as page number
    2. From memory, line number is calculated relative to top of page so extra code will be needed to calc from top of document.

    I could try having the code replicate the source documents so I could insert bookmarks but this will eventually cause space problems as the documents are and the scanned results are intended as an audit trail also. One instance where the code was applied meant it had to search 16Mb of text only MS Word documents so I am not sure that copies of the source files is the correct result.
    Further, some times the documents are provided from outside and are password protected to be read only.

    You would have thought that MS would provide a means of determining an absolute address for any given position in a document.

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

    Re: Hyperlink Subaddress (VBA Word 2003 Win XP)

    You don't need line numbers for this. Each range in a document has properties Start and End. They are long integers specifying where the range begins and ends, as a count of characters from the start of the document (including non-printing characters). You can obtain the Start and End of the selection (or range) when you have found a phrase, and store them in your target document. Later on, you can select the same range by retrieving the values:

    Dim lngstart As Long, lngEnd As Long
    lngStart = ...
    lngEnd = ...
    docSomething.Range(lngStart, lngEnd).Select

Posting Permissions

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