要使用VBA可依下列方式加入超連結
Sub nn()
Dim A As Range
For Each A In 檔案名稱的儲存格範圍(檔案名稱必須包含副檔名)
A.Hyperlinks.Add A, "E:\檔案目錄\" & A
Next
End Sub作者: syuan 時間: 2011-11-11 22:19
Worksheets("sheet1").Activate
For Each A In Worksheets("sheet1").UsedRange
If InStr(A, "JIS ") And A.Value = "" Then
B = "C:\11"
C = Dir(B, ".PDF")
A.Hyperlinks.Add A, C & A
End If
不過小弟發現如果將...... and A.value="" Then改為......and A.value <>""Then 時
現在的語法如下:
Dim A As Range
Dim B
Dim C
Worksheets("sheet1").Activate
For Each A In Worksheets("sheet1").UsedRange
If InStr(A, "JIS ") And A.Value = "" Then
B = "C:\11\"
C = Dir(B, ".PDF")
A.Hyperlinks.Add A, C & A
End If
Next A
小弟有加了這句語法"A.Hyperlinks.Add anchor:=A, Address:=B & A, TextToDisplay:=A"
發現還是無法讓VBA去連結路徑,路徑C:\11\依然被程式忽略過去。
小弟的程式碼如下:
Dim A As Range
Dim B
Dim C
Worksheets("sheet1").Activate
For Each A In Worksheets("sheet1").UsedRange
If InStr(A.Value, "JIS ") > 0 And A.Value <> "" Then
B = "C:\11\"
A.Hyperlinks.Add anchor:=A, Address:=B & A, TextToDisplay:=A
End If
Next A
而如果將這句裡的 If InStr(A.Value, "JIS ") > 0 And A.Value = "" Then改為 If InStr(A.Value, "JIS ") > 0 And A.Value <> "" Then
那麼執行後,就會出現一個對話框,寫著"執行階段錯誤'5': 程序呼叫或引數不正確"
而這句 If InStr(A.Value, "JIS ") > 0 And A.Value <> "" Then就會被程式反黃起來。