我在excel中有一个列,其中我有所有的网站url值。我的问题是我想把url值转换为活动链接。该列中大约有200个条目,所有单元格中都有不同的url。是否有一种方法可以在不编写宏的情况下创建到所有单元格的活动超链接。


当前回答

我发现,如果超链接不包括http://,因为它们链接到本地位置,那么这里的方法都不起作用。

我还想让脚本万无一失,因为用户无法自己维护它,而我也无法使用。

它只会在选定范围内包含点且没有空格的单元格上运行。它最多只能运行1万个细胞。

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

其他回答

如果你不想做一个宏,只要你不介意额外的列,那么就在你的url列旁边创建一个新列。

在公式中的新列类型=HYPERLINK(A1)中(将A1替换为您感兴趣的单元格)。然后将公式复制到剩下的200个条目中。

注意:如果单元格A1包含的字符串长度超过255个字符,则此解决方案不起作用。它的结果是#VALUE!错误

使用Windows上的Excel 2007,我发现这些步骤最简单;

选择具有非活动url的单元格 复制 粘贴为超链接

我有一个数字列表,馈送到url的我想热链接。 例如,我有一个列A的问题编号(即,2595692,135171),我想把这些问题编号转换为热链接,并只显示问题编号。

因此,我建立了一个指向列a的纯文本超链接,并将其复制下来用于我所有的问题编号:

=“=超链接(”&“”“http”&“”&“”/stackoverflow.com/questions/“&”&“”&A1&“)”

然后我复制粘贴值这一列的文本超链接到另一列。

你最终会得到如下所示的一列文本:

=超链接(“http”&“:”&“//stackoverflow.com/questions/2595692”,2595692)

然后我选择这些粘贴的项目,并运行F2Entry宏如下:

Sub F2Enter()
Dim cell As Range
Application.Calculation = xlCalculationManual
For Each cell In Selection
    cell.Activate
    cell = Trim(cell)
Next cell
Application.Calculation = xlCalculationAutomatic
EndSub

然后我删除了文本输入列和列A。

我最终得到了一列热链接的问题数字:

2595692

135171

etc.

干杯

最简单的方法

突出显示整个列 单击“插入” 点击“超链接” 点击“放入此文档” 单击ok 这是所有

我很惊讶Excel没有自动做这个,所以这是我的解决方案,我希望对其他人有用,

将整个列复制到剪贴板 在Chrome或Firefox上打开这个

data:text/html,<button onclick=“document.write(document.body.querySelector('textarea').value.split('\n').map(x => '<a href=</a>\'' + x + '\'>' + x + '').join(''))<br>”>Linkify</button><br><textarea></textarea>

将该栏粘贴到刚刚在浏览器上打开的页面上,然后按“链接”键 将结果从选项卡复制到Excel的列中

代替第二步,您可以使用下面的页面,首先,单击“运行代码片段”,然后将列粘贴在上面 <按钮onclick = " document . write (document.body.querySelector(文本区域).value.split(“\ n”)。地图(x = > < a href = \”+ x + '\'>' + x + < / >) . join(“< br >”))按钮“>其内< / > < br > < textarea > < / >文本区域