How do I convert a column of text URLs into active hyperlinks in Excel?

后端 未结 22 2153
刺人心
刺人心 2020-12-07 07:42

I have a column in excel, wherein I have all the website url values. My question is I want to turn the url values to active links. There are about 200 entries in that column

相关标签:
22条回答
  • 2020-12-07 08:24

    I found that none of the methods here worked if the hyperlink did not include http:// as they linked to local locations.

    I also wanted to fool-proof the script as the users would not be able to maintain it themselves and I would not be available.

    It will only run on cells in a selected range if they contain a dot and no spaces. It will only run for up to 10,000 cells.

    Sub HyperAdd()
    Dim CellsWithSpaces As String
        'Converts each text hyperlink selected into a working hyperlink
        Application.ScreenUpdating = False
        Dim NotPresent As Integer
        NotPresent = 0
    
        For Each xCell In Selection
            xCell.Formula = Trim(xCell.Formula)
            If xCell.Formula = "" Or InStr(xCell.Formula, ".") = NotPresent Then
            'Do nothing if the cell is blank or contains no dots
            Else
                If InStr(xCell.Formula, " ") <> 0 Then
                    CellsWithSpaces = CellsWithSpaces & ", " & Replace(xCell.Address, "$", "")
                     GoTo Nextxcell
                End If
    
                If InStr(xCell.Formula, "http") <> 0 Then
                    Hyperstring = Trim(xCell.Formula)
                Else
                    Hyperstring = "http://" & Trim(xCell.Formula)
                End If
    
                ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=Hyperstring
    
            End If
            i = i + 1
            If i = 10000 Then Exit Sub
    Nextxcell:
          Next xCell
        If Not CellsWithSpaces = "" Then
            MsgBox ("Please remove spaces from the following cells:" & CellsWithSpaces)
        End If
    Application.ScreenUpdating = True
    End Sub
    
    0 讨论(0)
  • 2020-12-07 08:29

    Easiest way here

    • Highlight the whole column
    • click ''insert''
    • click ''Hyperlink''
    • click ''place in this document''
    • click ok
    • thats all
    0 讨论(0)
  • 2020-12-07 08:31

    Thank you Cassiopeia for code. I change his code to work with local addresses and made little changes to his conditions. I removed following conditions:

    1. Change http:/ to file:///
    2. Removed all type of white space conditions
    3. Changed 10k cell range condition to 100k

    Sub HyperAddForLocalLinks()
    Dim CellsWithSpaces As String
        'Converts each text hyperlink selected into a working hyperlink
        Application.ScreenUpdating = False
        Dim NotPresent As Integer
        NotPresent = 0
    
        For Each xCell In Selection
            xCell.Formula = Trim(xCell.Formula)
                If InStr(xCell.Formula, "file:///") <> 0 Then
                    Hyperstring = Trim(xCell.Formula)
                Else
                    Hyperstring = "file:///" & Trim(xCell.Formula)
                End If
    
                ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=Hyperstring
    
            i = i + 1
            If i = 100000 Then Exit Sub
    Nextxcell:
          Next xCell
        Application.ScreenUpdating = True
    End Sub
    
    0 讨论(0)
  • 2020-12-07 08:33

    There is a very simple way to do this. Create one hyperlink, and then use the Format Painter to copy down the formatting. It will create a hyperlink for every item.

    0 讨论(0)
提交回复
热议问题