Excel VBA – 数据刷新后,添加超链接会丢失

我尝试从SQL视图更新数据后通过macros设置超链接。

当我在macros下面运行时,它会设置超链接(暂时),但是一旦完成,超链接又会消失。

如果我运行的超链接自行设置的一切工作,所以我相信它必须是导致问题的数据刷新。 对我来说,设置超链接后,再次调用刷新。

我的代码:

Sub loadData() With ActiveWorkbook.Connections("myConnection").OLEDBConnection .CommandText = "EXEC [dbo].[View] '" & Parameter & "'" ActiveWorkbook.Connections("myConnection").Refresh End With Call addHyperlink ' more code to follow.... Exit Sub End Sub Sub addHyperlink() Dim sht As Worksheet Dim LastRow As Long Set sht = ThisWorkbook.Worksheets("Data_Base") LastRow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row For i_count = 6 To LastRow If Worksheets("Data_Base").Range("B" & i_count).Value = "" Then Exit For Else Cells(i_count, 2).Hyperlinks.Add Anchor:=Cells(i_count, 2), _ Address:="http://www." & Cells(i_count, 2).Value, _ TextToDisplay:=Cells(i_count, 2).Value End If Next i_count End Sub 

我已经尝试了几种方法来修改数据刷新的属性,但没有运气。

有任何想法吗?