Log in

View Full Version : To fix "Run-time error '4198': Command failed" in macro to open hyperlinks



1819
03-11-2017, 02:26 PM
This little macro opens selected URLs in a Word document.... until it hits a dead link.

Then it reports "Run-time error '4198': Command failed" and stops.

Please could you tell me how to amend the code so that dead links are skipped, and the macro continues to open remaining valid links.

(I do not need the act of skipping to be reported or approved. It's acceptable simply to ignore dead links).

Many thanks



Sub OpenLinks()
Dim alink As Hyperlink
For Each alink In Selection.Hyperlinks
alink.Follow '<<<<<<<<<<<<<<<<<<<<<<Run-time error '4198': Command failed
Next alink
End Sub

Logit
03-11-2017, 06:28 PM
Try this :



Sub OpenLinks()
On Error Resume Next '<---- add this line

Dim alink As Hyperlink
For Each alink In Selection.Hyperlinks
alink.Follow '<<<<<<<<<<<<<<<<<<<<<<Run-time error '4198': Command failed
Next alink
End Sub

It's not a recommended method in coding but you stated skipping doesn't need to be approved or corrected.

1819
03-12-2017, 03:35 AM
Thanks, Logit, for a creative workaround but I'm getting this error. Please help.


18604


Try this :



Sub OpenLinks()
On Error Resume Next '<---- add this line

Dim alink As Hyperlink
For Each alink In Selection.Hyperlinks
alink.Follow '<<<<<<<<<<<<<<<<<<<<<<Run-time error '4198': Command failed
Next alink
End Sub

It's not a recommended method in coding but you stated skipping doesn't need to be approved or corrected.

Logit
03-12-2017, 07:51 AM
That's odd. I'm not receiving any errors at all here. Even if "On Error Resume Next" is commented out.

???

Here's what M$ has to say about it : https://msdn.microsoft.com/en-us/library/office/gg251623.aspx