在VBA中更新粘贴到外部电子表格的链接



我试图拦截粘贴外部链接的过程。我想改变链接到一个内部网站的来源。

公式如下:

='[filename.xlsx]Sheet1'!$B$7

我想把它改成:

='http://server/site/[filename.xlsx]Sheet1'!$B$7

下面的代码是这样做的:

Dim 
s As String s = ActiveCell.FormulaR1C1  
If Len(s) < 3 Then Exit Sub 
Dim i As Integer i = InStr(s, "[") 
If i > 0 Then
        s = "='X:directory[" + Mid(s, i + 1)
        ActiveCell.FormulaR1C1 = s
End If

我试着在前面添加

ActiveSheet.Paste Link:=True

但是它没有经过链接,而是粘贴了一个公式。我已经看过从剪贴板中提取链接,但没有任何运气与Application.ClipboardFormats。

尝试更改:

ActiveCell.FormulaR1C1 = s 

ActiveCell = s
ActiveSheet.Hyperlinks.Add Anchor:=ActiveCell, Address:=s

这样,你只放你想看的值,然后你添加超链接到你想要它指向的地方!没有理由与非常挑剔的Excel .Paste.PasteSpecial斗争。

最新更新