我在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

其他回答

您可以插入公式=HYPERLINK(<your_cell>,<your_cell>)到相邻的单元格,并将其一直拖到底部。这将为您提供一个包含所有链接的列。现在,您可以通过单击标题,右键单击并选择Hide来选择原始列。

创建宏如下所示:

在microsoftexcel的“工具”菜单上指向“宏”,然后单击“Visual Basic编辑器”。 在“插入”菜单上,单击“模块”。 将此代码复制并粘贴到模块的代码窗口中。 它会自动命名为HyperAdd。

Sub HyperAdd()

    'Converts each text hyperlink selected into a working hyperlink

    For Each xCell In Selection
        ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula
    Next xCell

End Sub

粘贴完宏后,单击“文件”菜单上的“关闭并返回到microsoftexcel”。

然后选择所需的单元格,单击宏,然后单击运行。

说明不要选择整个列!只选择单元格,你希望被改变为可点击的链接,否则你将结束在一个永无休止的循环,并必须重新启动Excel! 完成了!

最简单的方法

突出显示整个列 单击“插入” 点击“超链接” 点击“放入此文档” 单击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 > < / >文本区域

使用公式=HYPERLINK()创建一个临时的超链接新列 将该列复制到Microsoft Word(仅在Word运行后复制到剪贴板)。 复制新word文档中的所有内容(ctrl+a,然后ctrl+c)。 粘贴到Excel中,替换原来的文本列。使用公式删除临时列。