Hyperlinks (1 Viewer)

Thales750

Formerly Jsanders
Local time
Today, 03:09
Joined
Dec 20, 2007
Messages
2,112
Here is a question I asked the Chat GPT. It did not have a solution, just a few possible causes.

User
Why does this hyperlink not work with this type of address? It works great with most hyperlinks but not this one.
Non functional hyperlink, but works when pasted into browser.

1706043749638.png


Code:
Call GoHyperlink(Me.txtAttachment)

'Purpose:   Avoid warning and error messages when opening files with FollowHyperlink
'Author:    Allen Browne (allen@allenbrowne.com)
'Release:   28 January 2008
'Usage:     To open MyFile.doc in Word, use:
'               GoHyperlink "MyFile.doc"
'           instead of:
'               FollowHyperlink "MyFile.doc"
'Rationale:
'FollowHyperlink has several problems:
'   a) It errors if a file name contains characters such as #, %, or &.
'   b) It can give unwanted warnings, e.g. on a fileame with "file:///" prefix.
'   c) It yields errors if the link did not open.
'This replacement:
'   a) escapes the problem characters
'   b) prepends the prefix
'   c) returns True if the link opened (with an optional error message if you care.)
'Limitations:
'   - If a file name contains two # characters, it is treated as a hyperlink.
'   - If a file name contains % followed by 2 hex digits, it assumes it is pre-escaped.
'   - File name must include path.
'Documentation:   http://allenbrowne.com/func-GoHyperlink.html
Public Function GoHyperlink(FullFilenameOrLink As Variant) As Boolean
    On Error GoTo Err_Handler
    'Purpose:   Replacement for FollowHyperlink.
    'Return:    True if the hyperlink opened.
    'Argument:  varIn = the link to open
    Dim strLink As String
    Dim strErrMsg As String

    'Skip error, null, or zero-length string.
    If Not IsError(FullFilenameOrLink) Then
        If FullFilenameOrLink <> vbNullString Then
            strLink = PrepHyperlink(FullFilenameOrLink, strErrMsg)
            If strLink <> vbNullString Then
                FollowHyperlink strLink
                'Return True if we got here without error.
                GoHyperlink = True
            End If
            'Display any error message from preparing the link.
            If strErrMsg <> vbNullString Then
                MsgBox strErrMsg, vbExclamation, "PrepHyperlink()"
            End If
        End If
    End If

Exit_Handler:
    Exit Function

Err_Handler:
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "GoHyperlink()"
    Resume Exit_Handler
End Function

Hopefully this will be one of those time where a human will outperform an AI.

Thanks all.
 
Last edited:

Edgar_

Active member
Local time
Today, 02:09
Joined
Jul 8, 2023
Messages
430
Your link is wrong, also, youtube links that come from share features usually redirect.
 

Thales750

Formerly Jsanders
Local time
Today, 03:09
Joined
Dec 20, 2007
Messages
2,112
Your link is wrong, also, youtube links that come from share features usually redirect.
Yes the forum added that. I'm changing that.
Is there any way to deal with the redirect.
 

Edgar_

Active member
Local time
Today, 02:09
Joined
Jul 8, 2023
Messages
430
Use shell, maybe?
Code:
Dim url As String: url = "theurl.url/url"
Shell "cmd /c start " & url, vbNormalFocus

Obviously use the right url
 

isladogs

MVP / VIP
Local time
Today, 08:09
Joined
Jan 14, 2017
Messages
18,221
I'm a huge fan of Allen Browne's work but I don't use GoHyperlink.
For something like this why not just use FollowHyperlink which does work e,g.
Code:
Application.FollowHyperlink "https://www.youtube.com/watch?v=NxCFDZcDXQk"
 
Last edited:

Thales750

Formerly Jsanders
Local time
Today, 03:09
Joined
Dec 20, 2007
Messages
2,112
I.m a huge fan of Allen Browne's work but I don't use GoHyperlink.
For something like this why not just use FollowHyperlink which does work e,g.
Code:
Application.FollowHyperlink "https://www.youtube.com/watch?v=NxCFDZcDXQk"
Because once I learn something I usually keep doing it forever, or until I have a reason to switch. which, apparently I do.

I could probably be smarter I guess, just ask my EXs.
 

Thales750

Formerly Jsanders
Local time
Today, 03:09
Joined
Dec 20, 2007
Messages
2,112
I.m a huge fan of Allen Browne's work but I don't use GoHyperlink.
For something like this why not just use FollowHyperlink which does work e,g.
Code:
Application.FollowHyperlink "https://www.youtube.com/watch?v=NxCFDZcDXQk"
One question though. I have "links" to multiple types in the same field. so in one row it may open a file. In another, it may open a website.
Will FollowHyperlink open folders or files?
 

Thales750

Formerly Jsanders
Local time
Today, 03:09
Joined
Dec 20, 2007
Messages
2,112
I'm a huge fan of Allen Browne's work but I don't use GoHyperlink.
For something like this why not just use FollowHyperlink which does work e,g.
Code:
Application.FollowHyperlink "https://www.youtube.com/watch?v=NxCFDZcDXQk"
Thank you Colin
 

isladogs

MVP / VIP
Local time
Today, 08:09
Joined
Jan 14, 2017
Messages
18,221
You're welcome.
AFAIAA the only thing that FollowHyperlink fails on is that it doesn't open the default email app for email addresses.
For that, I often use Dev Ashish's fHandeleFile function
 

Users who are viewing this thread

Top Bottom