我在Excel中有一列,其中包含所有网站URL的值。我的问题是,我想将这些URL值转换为活动链接。该列中有大约200个条目,所有单元格中的URL都不同。是否有一种方法可以在不编写宏的情况下为所有单元格创建活动超链接。
我在Excel中有一列,其中包含所有网站URL的值。我的问题是,我想将这些URL值转换为活动链接。该列中有大约200个条目,所有单元格中的URL都不同。是否有一种方法可以在不编写宏的情况下为所有单元格创建活动超链接。
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的列复制到另一个应用程序(比如Evernote)中,当它们被粘贴到那里时,它们变成了链接,然后我再将它们复制回Excel。
唯一需要注意的是,你需要确保你复制回来的数据与其他列对齐。
=HYPERLINK("http://"&B10,B10)
在你的原始列上使用$
,使其看起来像这样:
=HYPERLINK("http://"&$B10,$B10)
这是我在Windows 7上的Excel 2010中唯一有效的方法。您可以拖动公式以复制。
我将它们放入一个HTML文件(links.html)中,就像这样:https://twitter.com/keeseter/status/578350771235872768/photo/1 https://instagram.com/p/ys5ASPCDEV/ https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10881854_329617847240910_1814142151_n.jpg https://twitter.com/ranadotson/status/539485028712189952/photo/1 https://instagram.com/p/0OgdvyxMhW/ https://instagram.com/p/1nynTiiLSb/
<table>
<tr><td><a href="https://twitter.com/keeseter/status/578350771235872768/photo/1">https://twitter.com/keeseter/status/578350771235872768/photo/1</a></td></tr>
<tr><td><a href="https://instagram.com/p/ys5ASPCDEV/">https://instagram.com/p/ys5ASPCDEV/</a></td></tr>
<tr><td><a href="https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10881854_329617847240910_1814142151_n.jpg">https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-15/10881854_329617847240910_1814142151_n.jpg</a></td></tr>
<tr><td><a href="https://twitter.com/ranadotson/status/539485028712189952/photo/1">https://twitter.com/ranadotson/status/539485028712189952/photo/1</a></td></tr>
<tr><td><a href="https://instagram.com/p/0OgdvyxMhW/">https://instagram.com/p/0OgdvyxMhW/</a></td></tr>
</table>
=HYPERLINK(<your_cell>,<your_cell>)
,并将其沿着底部拖动。这将给你一列所有链接。现在,你可以通过点击标题选择原始列,右键单击并选择隐藏
。http:/
更改为file:///
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
NotPresent
? - Steffen Roller="=HYPERLINK("&"""http""&"":"""&""&"&"&"""//stackoverflow.com/questions/"&A1&""""&","&A1&")"
然后我将这一列文本超链接的值复制 - 粘贴到另一列中。
最终你会得到一个看起来像下面这样的文本列:
=HYPERLINK("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
等等。
谢谢。