Macro fails to produce any results

H

halletts

I have a large number of my own help documents that I keep on a zip
disk and whose links I access from a word document. Ater installing
Windows XP and s new CD burner the drive letter for the zip drive has,
of course, changed. Using VB6 to save the tedeum of manually changing
all the links from J: to L:. I wrote the following code as a module :

Public Sub test()
Dim i As Integer
Dim HlinkName As String
With ActiveDocument.Hyperlinks
For i = 1 To ActiveDocument.Hyperlinks.Count
HlinkName = ActiveDocument.Hyperlinks(i).Name
If Left$(HlinkName, 2) = "J:" Then
HlinkName = "L:" & Mid$(HlinkName, 3)
End If
Next i
End With

End Sub

When run nothing happens so I attempted to debug. Using step into and
viewing the locals window I can see that the call stack marker stops
at what seems the appropriate lines, the values in the locals windows
for I and HlinkName move though the links with no error messages
returned but when run as a macro or inserted as a document open event
still does not change the relevant link destinations.
Obviously I'm missing something pretty basic to have my code run
without errors and yet not produce any results.
Any suggestions?
Thanks,
Ed
 
J

Jay Freedman

Hi, Ed,

Actually you have two (or maybe three) misunderstandings going on here.

First, you're assigning a new value to the String variable HlinkName, but
you're never doing anything with that value to change the hyperlink. That's
why nothing visible happens in the document.

Next, the .Name property of the hyperlink is the wrong property. The .Name
property of a hyperlink is a read-only property, so if you try to assign the
revised HlinkName to it, you'll get an error. Besides that,

There are actually *two* other properties that you need to change. One is
the .TextToDisplay property, which contains the string that appears in the
document. The other is the .Address property, which contains the URL that's
the target of the hyperlink. You probably want to change both of them, but
..Address is the more important one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top