Exceeding Max Char Limit in Excel

后端 未结 11 1672
名媛妹妹
名媛妹妹 2020-12-10 06:51

How do I use more than 255 characters in Excel\'s CONCATENATE function? I am actually also using the CONCATENATE function within the HYPERLINK function in EXCEL. An example

11条回答
  •  感情败类
    2020-12-10 07:45

    Here's some VBA which uses bitly.com to shorten a URL. It is based on the bitly API documentation.

    1. Create a free account on bitly.
    2. Valid email address with bitly.
    3. Get access token from bitly.
    4. Substitute the access token in the VBA code below where it says MY_TOKEN.
    5. Copy and paste the code in Excel's VBA.
    6. In a cell, write the following '=Hyperlink(GetURL("some really long URL"))' without single quote ' marks. Note: Instead of passing a string to GetURL(), pass a reference to a cell which has a URL in it as text.
    Public Function GetURL(longUrl As String) As String
      Dim xml As Object
    
      longUrl = URLEncode(longUrl)
      Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
    
      xml.Open "GET", "https://api-ssl.bitly.com/v3/shorten?format=xml&access_token=MY_TOKEN=" & longUrl, False
      xml.Send
    
      GetURL = xml.responsetext
    
      head = InStr(GetURL, "") + 5
      tail = InStr(GetURL, "")
    
      GetURL = Mid(GetURL, head, tail - head)
    
    End Function
    
    Function URLEncode(ByVal Text As String) As String
      Dim i As Integer
      Dim acode As Integer
      Dim char As String
      URLEncode = Text
      For i = Len(URLEncode) To 1 Step -1
        acode = Asc(Mid$(URLEncode, i, 1))
        Select Case acode
          Case 48 To 57, 65 To 90, 97 To 122
            ' don't touch alphanumeric chars
          Case 32
            ' replace space with "+"
            Mid$(URLEncode, i, 1) = "+"
          Case Else
            ' replace punctuation chars with "%hex"
            URLEncode = Left$(URLEncode, i - 1) & "%" & Hex$(acode) & Mid$(URLEncode, i + 1)
        End Select
      Next
    End Function
    

提交回复
热议问题