我在excel中有一个列,其中我有所有的网站url值。我的问题是我想把url值转换为活动链接。该列中大约有200个条目,所有单元格中都有不同的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.

干杯

其他回答

我发现,如果超链接不包括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("http://"&B10,B10)

其中B10是包含URL文本版本的单元格(在本例中)。

创建宏如下所示:

在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! 完成了!

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

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

对我来说,我只是复制了整个列,其中有文本格式的url到另一个应用程序(说Evernote),当他们粘贴在那里,他们成为链接,然后我只是复制回Excel。

这里唯一需要做的是确保复制回来的数据与其余列对齐。