Consulting

Results 1 to 4 of 4

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

  1. #1
    VBAX Regular
    Joined
    Oct 2014
    Posts
    95
    Location

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

    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

  2. #2
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    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.

  3. #3
    VBAX Regular
    Joined
    Oct 2014
    Posts
    95
    Location

    "Compile error: External name not defined"

    Thanks, Logit, for a creative workaround but I'm getting this error. Please help.


    Error.jpg

    Quote Originally Posted by Logit View Post
    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.

  4. #4
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    606
    Location
    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/lib.../gg251623.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •