cant get activedocument.Hyperlinks(1).Address throws 4198 command failed

J

Jason Eacott

Hi all,
this is related to my last question about Hyperlinks containing
Paragraph marks.
eg: if (P) is a paragraph mark and both these lines have hyperlinks AND
the (P) is included in the hyperink(shows blue):
text (P)
moretext(P)
then I can only get the address of the last link.
activedocument.Hyperlinks(1).Address throws error 4198 command failed.

I have also tried it by stepping to each character in the first line with a
range.next
type of construct and trying to get the hyperlink address that way - but no
luck.
This looks like a typical MS bug, but does anyone have a workaround?
or an explanation?

Thanks in Advance.
Jason.
 
C

Chad DeMeyer

Jason,

Since you refer to blue text I am making the assumption that the text of the
hyperlink matches its address. In that case, try:

activedocument.hyperlinks(1).texttodisplay

Hope that helps
Regards,
Chad
 
J

Jason Eacott

actually that just completely crashes Word!
I have solved it with this piece of magic, but if anyone has a cleaner
method please let me know. It has taken me quite some time to find something
that works. It both "moves" the paragraph marks outside the hyperlink fields
AND solves the 4198 problem.

heres my code:
Public Sub StripParasFromHyperlinks(doc As Document)
Dim fldItem As Word.Field
Dim myrange As Range
Dim dr As Range
' Enumerate the Main Text Stories Fields collection
cnt = doc.Fields.Count
For i = 1 To cnt
Set fldItem = doc.Fields(i)
' We're only interested in Hyperlink fields
If fldItem.Type = wdFieldHyperlink Then
If InStr(1, fldItem.result.text, vbCr, vbTextCompare) Then
Set myrange = fldItem.result
fldItem.result.text = Replace(fldItem.result, vbCr, "")
Set dr = doc.Range(myrange.Start, myrange.Start)
fldItem.Cut 'This is such a hack! go Microsoft!!!
dr.InsertParagraphAfter
dr.Paste 'yech
dr.InsertParagraphAfter
End If
End If
Next
'*Note TODO. if alt-f9 has been pressed at any time then this will
return pasted fields as showing fieldcodes.
' this should be switched off for all fields affected here.
End Sub ' StripParasFromHyperlinks

thanks again ALL
 
Top