Hi Ray,
This code works for me:
Sub HLinkTest()
Dim HLink As Hyperlink
With ActiveDocument
.Range.AutoFormat
For Each HLink In .Hyperlinks
If Left(HLink.Address, 7) = "mailto:" Then MsgBox HLink.Address
Next
End With
End Sub
and I'm unable to reproduce either of the error messages you mentioned - even if I change the hyperlink address to
"outbind:\\1000510063444" or "mailto:outbind:\\1000510063444".
With your hyperlinks, what do you see when you press Alt-F9? This exposes the field coding and you should see something like:
{HYPERLINK "mailto:here@there.com"}. Note that the display text is not necessarily the hyperlink address.
Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
"Ray C"
>I already tried that and I still get the same error. The problem is that the
> HLink instance seems deleted when it starts executing the first line inside
> the For loop. One thing I noticed is that when I click on the hyperlinks
> inside the Word document itself, nothing happens. When I look at the address
> of the hyperlink (using Word, not VBA) the address has strange characters. It
> has "outbind:\\1000510063444"
>
> But Word still has the email address as a hyperlink and the text does show
> name@domain.com
>
> Ray
>
>
> "macropod" wrote:
>
>> Hi Ray,
>>
>> How about:
>> Dim HLink As Hyperlink
>> objDocument.Range.AutoFormat
>> For Each HLink In objDocument.Hyperlinks
>> If Left(HLink.Address, 7) = "mailto:" Then
>> ....
>> End If
>> ....
>> Next
>>
>> Cheers
>> --
>> macropod
>> [MVP - Microsoft Word]
>> -------------------------
>>
>> "Ray C"
>> > I'm writing a Word VBA function that process hyperlinks within word
>> > documents. Since Work can also convert web sites into hyperlinks as well, I
>> > check that the Hyperlink.Address property begins with "mailto" to make sure I
>> > only process email addresses.
>> >
>> > Here's a sample of my code:
>> >
>> > objDocument.Range.AutoFormat
>> > For Each HLink In objDocument.Hyperlinks
>> > E_Mail = Split(HLink.Address, ":", 1)
>> > If E_Mail(0) = "mailto" Then
>> > ....
>> > Endif
>> > ......
>> > Endif
>> >
>> > The problem is that I get an error on the third line, telling me that
>> > Hyperlink has been deleted. Yet I clearly have two email addresses in the
>> > document. In other cases I get a different error message saying that the
>> > Address method of object Hyperlink failed (caused by the same line, the third
>> > line).
>> >
>> > When I step code during debugging, I get 2 for objDocument.Hyperlinks.Count
>> > which is what I'm supposed to get since there are 2 hyperlinks in the
>> > document.
>> >
>> > Can anyone shed some light on this?
>> >
>> > Thanks in advance
>> >
>> > Ray
>> >
>>