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

时间:2015-06-25 07:10:47

标签: excel vba excel-vba hyperlink

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

当我在宏下运行时,它确实设置了超链接(暂时),但一旦完成,超链接就会再次消失。

如果我运行sub设置自己的超链接一切正常,所以我认为它必须是导致问题的数据刷新。对我来说,看起来在设置超链接后再次调用刷新。

我的代码:

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

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

有什么想法吗?

0 个答案:

没有答案
相关问题