Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Editing Word 97 hyperlink addresses under program control.

I am trying to write a program to edit hyperlink addresses in a range of Word 97 documents.  I can read the addresses from the Hyperlinks collection of each document but I can't figure out how to update them as the address field is read only.
I looked at deleting and adding but add requires the object containing the hyperlink and this does not seem to be available from the hyperlink object.

Any help would be appreciated.

Regards

Bob
0
beezee
Asked:
beezee
1 Solution
 
dmangCommented:
Hi beezee ...

I use the sub below to convert hyperlinks that refer to .doc files, to hyperlinks that refer to .htm files.
This is contained in a word document, so I do not have to reference the Word object library. Keep in mind that the hyperlink must be tied to some words in the document.

The process does the following:
for each hyperlink.
  if link address contains .doc then
     store the link removing the .doc extension)
     delete the link
     select the initial text and set as anchor
     add the hyperlink at the same location
  end if
next link

Sub convert_link_to_HTM()

    Dim i As Integer, _
        iwords As Integer, _
        ipos As Integer
       
   
    With ActiveDocument
   
        For i = 1 To .Hyperlinks.Count
            ipos = InStr(1, .Hyperlinks(i).Address, ".doc")
            If ipos > 0 Then
                straddr = Left(.Hyperlinks(i).Address, ipos - 1)
                .Hyperlinks(i).Range.Select
                iwords = Selection.Words.Count
                .Hyperlinks(i).Delete
                Selection.MoveRight Unit:=wdWord, Count:=iwords, Extend:=wdExtend
                .Hyperlinks.Add Anchor:=Selection.Range, _
                    Address:=straddr & ".htm", _
                    SubAddress:=""
            End If
        Next i
   
    End With

End Sub
0
 
beezeeAuthor Commented:
Hi Dmang

Thanks for your reply.  I try your suggestion.

The only possible problem is that some of the hyperlinks are in command buttons embedded in the document.  Do yoy think that your code will handle that?

Regards

Bob
0
 
dmangCommented:
I'm not sure if those links will be part of the collection. If so, the anchor will likely be different - not being document text.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
beezeeAuthor Commented:
Dmang

Thanks for your reply.

I found that the Hyperlinks(i).Shape is the one I needed.  This even returns hyperlinks in text as well as command buttons.

Regards

Bob
0
 
CleanupPingCommented:
Hi beezee,
This old question (QID 20560371) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->PAQ - with points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now