คำตอบ Excel Hyperlink length limitations

  • 25 มกราคม 2555 19:44
     
     
    Is there a way to create a hyperlink in a cell that concatenates the values of two other cells and is longer then the hyperlink function max characters?  I need to link to a URL that is made up of a base url concatenated to a value picked from a drop-down.  The resulting URL is 300+ characters and causes the hyperlink function to error.  I am looking for a solution that does not require a macro or any kind of add-in.

ตอบทั้งหมด

  • 25 มกราคม 2555 20:12
     
     คำตอบ มีโค้ด

    That is not that hard

    Two columns A2 one part of link, B2 dn part, and some hundred rows.

    VBA Code:

    Sub hiperlink_to_web()
    Dim X&, last_row&: last_row = Cells(Rows.Count, "a").End(xlUp).Row
    For X = 2 To last_row
        ActiveSheet.Hyperlinks.Add Anchor:=Cells(X, 3), _
                    Address:=Cells(X, "A") & Cells(X, "B"), _
                    TextToDisplay:=Cells(X, 2).Value
    Next X
    End Sub
    

    fig. HiperLink name is from 2nd part

    Regatds


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    • ทำเครื่องหมายเป็นคำตอบโดย Max MengMicrosoft, Moderator 9 มีนาคม 2555 8:57
    •  
  • 4 กรกฎาคม 2555 17:15
     
     

    Hi, my worksheet has 50000 rows.  When i give hyperlink by using vba code it gives error at row 21845.  After this row not able to give hyperlink.  Is there any limit or rows to provide the hyperlinks? Thanks in advance.


    The error is "1004 Application-defined or object-defined error"
    • แก้ไขโดย Poov 4 กรกฎาคม 2555 17:19
    •  
  • 6 กรกฎาคม 2555 7:34
     
     คำตอบที่เสนอ มีโค้ด

    Poov, code from my post count max row - so no matter how many rows you've got.

    This error is comes from date you're using.

    Link example of your file, or modyf this code like this:

    Sub hiperlink_to_web()
    Dim X&, last_row&: last_row = Cells(Rows.Count, "a").End(xlUp).Row
    For X = 2 To last_row
    on error goto blad
        ActiveSheet.Hyperlinks.Add Anchor:=Cells(X, 3), _
                    Address:=Cells(X, "A") & Cells(X, "B"), _
                    TextToDisplay:=Cells(X, 2).Value
    dalej:
    Next X
    exit sub
    blad:
     msgbox "This rows cannot have url string!" & vbcr & _
    Error no: " & err.nr & vbcr & _
    err.description, vbExclamation
    resume dalej
    End Sub
    that modyfication inform you, about error in the row, and resume next row.

    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    • เสนอเป็นคำตอบโดย Poov 28 สิงหาคม 2555 15:38
    •  
  • 28 สิงหาคม 2555 15:38
     
     
    Hello Oskar Shon,  Thanks for the code - Error in my code, special character in that cell.