2017-10-14 154 views
0

該系列命令似乎導致運行時錯誤:1004我想知道導致此錯誤的原因是什麼。Excel VBA:嘗試添加超鏈接時出現錯誤1004

如果我沒有Activesheet.Hyperlinks.add行的單元格值設置正確,只是缺少超鏈接...這會讓我覺得我已經失去了xCell引用,但我已經將調試語句放在了在hyperlink.add之前,它似乎是可訪問的。

實例網址:http://www.walmart.com/ip/Transformers-Robots-in-Disguise-3-Step-Changers-Optimus-Prime-Figure/185220368

For Each xCell In Selection 
    Url = xCell.Value 
    If Url = "" Then 
     'Do Nothing 
    ElseIf IsEmpty(xCell) = True Then 
     'Do Nothing 
    ElseIf IsEmpty(Url) = False Then 
     splitArr = Split(Url, "/") 
     sku = splitArr(UBound(splitArr)) 
     xCell.Value = "https://www.brickseek.com/walmart-inventory-checker?sku=" & sku 
     'Error happens on next command 
     ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=xCell.Formula 
    End If 
Next xCell 

回答

1

不要都與.value的
不要使用.Formula

Sub demo() 
    Dim s As String, xCell As Range 

    s = "http://www.walmart.com" 
    Set xCell = Range("B9") 
    ActiveSheet.Hyperlinks.Add Anchor:=xCell, Address:=s, TextToDisplay:=s 
End Sub 

是一個典型的工作示例。

+0

爲了澄清,我的命令序列的問題是,我設置了var xCell的值,然後嘗試使用添加超鏈接修改同一個單元格。通過僅設置一個變量「s」,並且只有調用add超鏈接纔會停止正在導致的xCell的解除引用?你的解決方案工作我只是不知道我確切知道爲什麼。謝謝。 –

相關問題