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


当前回答

如果你复制文本内容到一个新的列,并使用:

=HYPERLINK("http://"&B10,B10) 

在你原来的专栏上。然后使用$的列,使它看起来像这样:

=HYPERLINK("http://"&$B10,$B10)

这是我在Windows 7上使用Excel 2010的唯一方法。你可以把这个公式抄下来。

其他回答

我发现,如果超链接不包括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

在Mac上,一个非常简单的方法就是在Excel中选择整个电子表格,复制,启动Numbers,粘贴,然后全选,复制,粘贴回Excel中。

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

选择具有非活动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! 完成了!

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

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

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