Questions: Infinite Loops, Hyperlinks

D

Dan Perkins

1) I am working on a rather complex macro, and occassionaly make a little
mistake. Unfortunately, being that I am looping through my document, this
often leads to an infinite loop. How can I stop the macro, without closing
Word (which results in me losing my changes to the macro).

2) Is there a way in macro code to recogize that I am on a line of text that
has a hyperlink in it, and to access the hyperlink detail?
 
J

Jonathan West

Dan Perkins said:
1) I am working on a rather complex macro, and occassionaly make a little
mistake. Unfortunately, being that I am looping through my document, this
often leads to an infinite loop. How can I stop the macro, without closing
Word (which results in me losing my changes to the macro).

Press Ctrl-Break to stop the macro.
2) Is there a way in macro code to recogize that I am on a line of text
that
has a hyperlink in it, and to access the hyperlink detail?

Dim oLink as Hyperlink
If Selection.Paragraphs(1).Range.Hyperlinks.Count > 0 Then
Set oLink = Selection.Paragraphs(1).Range.Hyperlinks(1)
'Do whatever you want with the link here
End If

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Dan,

[ctrl break] plus

Application.EnableCancelKey = wdCancelInterrupt
just in case it was set to wdCancelDisabled.

But I always forget about that.

So I use a counter that stops the program
if the value of the counter gets too high.

With Selection.Bookmarks("\line").Range
If .Hyperlinks.Count > 0 Then
MsgBox "hyperlink"
MsgBox .Hyperlinks(1).Address
' I am not quite sure here
End If
End With

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Dan Perkins

Jonathan and Helmut, thank you both for your help, I appreciate it very much.
 

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