Group: microsoft.public.word.vba.general
From: "macropod"
Date: Wednesday, March 26, 2008 5:02 PM
Subject: Re: Hyperlink problem in vba

Hi Ray,

I'm not surprised that either of those fields failed - they're not valid hyperlinks. You can see that by the "" in the field, which
basically says the hyperlink is nothing. If you were to manually create a hyperlink field with that code and no alternate display
text, Word would return an error message on the page.

You can use the following code to get around that:
Sub HLinkTest()
Dim oFld As Field
With ActiveDocument
.Range.AutoFormat
For Each oFld In .Fields
If oFld.Type = wdFieldHyperlink Then
If Left(oFld.Result, 7) = "mailto:" Then MsgBox oFld.Result
End If
Next
End With
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"Ray C" wrote in message news:394179E5-4534-453E-A0CE-937CC53C25AC@microsoft.com...
> Hi macropod,
>
> When I press ALT-F9
> For the first hyperlink I have:
>
> {HYPERLINK "" \o
> "outbind://115-00000000C02DC307E8EC334F91A9B8DEBCE1EBBD44CF2800/"}
>
> and for the second hyperlink I have:
>
> { HYPERLINK "" \o
> "outbind://115-00000000C02DC307E8EC334F91A9B8DEBCE1EBBD44CF2800/" }
>
>
> Yes, with all the spaces (weird).
>
> When I toggle out of ALT-F9, the email addresses are actually valid.
> I get the error message when I reach the line:
> If Left(HLink.Address, 7) = "mailto:" Then MsgBox HLink.Address
>
> It can't read the Address property of the HLink because it claims that HLink
> was deleted.
>
> Ray
>
> "macropod" wrote:
>
>> 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" wrote in message news:5E64A8B6-2414-4B44-A789-9B31DAD320A3@microsoft.com...
>> >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" wrote in message news:82EDD7AD-95B7-4BEC-A532-2DE77D09E3DF@microsoft.com...
>> >> > 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
>> >> >
>> >>
>>
>>

Safety Articles | Usenet Groups | Usenet News | Bluegrass