更新Excel文件中的所有链接

时间:2014-11-09 09:55:02

标签: c# excel

我有excel文件,其中包含大量信息,一列包含我硬盘中的文件URL链接。但是硬盘名称从F变为G并且所有链接都被破坏。我是否可以轻松更新链接,而无需编写完成此任务的新应用程序。

example

1 个答案:

答案 0 :(得分:2)

这样的VBA可以起作用:

Sub HyperLinkChange()
   Dim oldtext As String
   Dim newtext As String
   Dim h As Hyperlink

   oldtext = "F:\"
   newtext = "G:\"
       For Each h In ActiveSheet.Hyperlinks
       x = InStr(1, h.Address, oldtext)
       If x > 0 Then
           h.Address = Application.WorksheetFunction. _
           Substitute(h.Address, oldtext, newtext)
       End If
       Next
End Sub