none
Paste Hyperlink RRS feed

  • Question

  • Hello ,

    I have a problem with my link, after paste it in the cell it did not open but when I selected and make Enter can I open it .

    how can I open my link without this select and Enter ?

    newPath is a link

    with Worksheets ("Sheet1")
    	lRow = .Cells(Rows.Count, 7).End(xlUp).Row
    	.Cells(lRow, 7) = newPath 
    	End with 

    Best regards,

    Neven

    Friday, June 15, 2018 8:14 AM

Answers

  • Try the following. Note that I have provided 2 options of code. First option to open using the newPath string and the second to use the cell to which the string is written.(Only use one of the options or it will attempt to open the file twice.)

    Code edited since initial posting. This example actually creates the HyperLink on the worksheet.

    Sub OpenLinkTest()

        Dim newPath As String
        Dim lRow As Long
       
        newPath = ThisWorkbook.Path & "\" & "Dealer Validation.xlsm"    'for testing code
       
        With Worksheets("Sheet1")
            lRow = .Cells(Rows.Count, 7).End(xlUp).Row
           
            .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=newPath
           
            ThisWorkbook.FollowHyperlink (newPath)      'Option 1
            'ThisWorkbook.FollowHyperlink (.Cells(lRow, 7))  'Option 2
        End With
    End Sub


    Regards, OssieMac


    • Edited by OssieMac Sunday, June 17, 2018 2:12 AM
    • Marked as answer by Req_En Monday, June 18, 2018 6:59 AM
    Sunday, June 17, 2018 1:53 AM
  • .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=newPath

    In the TextToDsiplay parameter. In my previous example I just used NewPath but it can be any text string enclosed in double quotes like the following.

    .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:="My Description"

    Alternatively you can set a variable as follows (Note that the variable in the hyperlink is not enclosed in double quotes)

            strDisplay = "My Description"
           
            .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=strDisplay


    Regards, OssieMac

    • Marked as answer by Req_En Monday, June 18, 2018 7:54 AM
    Monday, June 18, 2018 7:29 AM

All replies

  • Try the following. Note that I have provided 2 options of code. First option to open using the newPath string and the second to use the cell to which the string is written.(Only use one of the options or it will attempt to open the file twice.)

    Code edited since initial posting. This example actually creates the HyperLink on the worksheet.

    Sub OpenLinkTest()

        Dim newPath As String
        Dim lRow As Long
       
        newPath = ThisWorkbook.Path & "\" & "Dealer Validation.xlsm"    'for testing code
       
        With Worksheets("Sheet1")
            lRow = .Cells(Rows.Count, 7).End(xlUp).Row
           
            .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=newPath
           
            ThisWorkbook.FollowHyperlink (newPath)      'Option 1
            'ThisWorkbook.FollowHyperlink (.Cells(lRow, 7))  'Option 2
        End With
    End Sub


    Regards, OssieMac


    • Edited by OssieMac Sunday, June 17, 2018 2:12 AM
    • Marked as answer by Req_En Monday, June 18, 2018 6:59 AM
    Sunday, June 17, 2018 1:53 AM
  • Hello OssieMac,

    thank u , it work's perfect .

    I have another quesiton please , my links paths are so lang how can I show just a part of links text in my Cell ?

    e.g. C:\user\Program\test\code\01_Matlab = > \code\01_Maltlab

    Best regards,

    Neven

    Monday, June 18, 2018 7:07 AM
  • .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=newPath

    In the TextToDsiplay parameter. In my previous example I just used NewPath but it can be any text string enclosed in double quotes like the following.

    .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:="My Description"

    Alternatively you can set a variable as follows (Note that the variable in the hyperlink is not enclosed in double quotes)

            strDisplay = "My Description"
           
            .Hyperlinks.Add Anchor:=.Cells(lRow, 7), Address:= _
                                    newPath, TextToDisplay:=strDisplay


    Regards, OssieMac

    • Marked as answer by Req_En Monday, June 18, 2018 7:54 AM
    Monday, June 18, 2018 7:29 AM
  • thank u very much.

    Best regards,

    Neven

    Monday, June 18, 2018 7:54 AM