跳到主要內容

 如何通過單擊Excel中的超鏈接運行宏?

宏代碼對於我們解決Excel中的一些複雜工作可能非常有幫助,通常,我們可以在 適用於應用程序的Microsoft Visual Basic 通過單擊窗口 按鈕或按下 F5 鍵。 但是,您是否曾經嘗試過通過單擊工作表中的相對超鏈接來運行宏?

通過單擊帶有VBA代碼的超鏈接來運行或執行宏


箭頭藍色右氣泡 通過單擊帶有VBA代碼的超鏈接來運行或執行宏

通過單擊Excel中的超鏈接來觸發宏可能對我們來說很有趣,以下方法可以幫助您逐步實現此任務:

1。 創建要用於執行宏代碼的超鏈接。 請單擊一個單元格並創建一個超鏈接以鏈接到其自身,請參見屏幕截圖:

doc從超鏈接1運行宏

2。 重複上述步驟以創建您要使用的其他超鏈接,如以下屏幕截圖所示:

doc從超鏈接2運行宏

3。 然後右鍵單擊包含要使用的超鏈接的工作表選項卡,然後選擇 查看代碼 從上下文菜單中,然後在打開的 適用於應用程序的Microsoft Visual Basic 窗口,將以下代碼複製並粘貼到空白模塊中:

VBA代碼:從超鏈接運行宏代碼:

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    If Target.Range.Address = "$B$6" Then
        Call Macro1
        End If
         If Target.Range.Address = "$B$8" Then
        Call Macro2
         End If
End Sub

doc從超鏈接3運行宏

備註:在上面的代碼中, B6 B8 單元格是否包含您要使用的超鏈接,並且 Macro1 Macro2 是宏代碼名稱,請根據需要進行更改。

4。 然後保存並關閉代碼窗口,從現在開始,單擊超鏈接時,將立即執行特定的宏代碼。


相關文章:

Excel中單元格值更改時如何運行宏?

如何在Excel中根據單元格值運行宏?

如何基於從Excel的下拉列表中選擇的值運行宏?

如何在Excel中打印之前自動運行宏?

從工作簿中選擇工作表時如何運行宏?

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
works well
This comment was minimized by the moderator on the site
Me sale un error:

Error de compilación:
No se ha definido Sub o Function
This comment was minimized by the moderator on the site
Olá,

Um dos poucos locais onde encontrei essa solução. Muito obrigado! Estou quase lá. Não estou usando uma célula para o hiperlink, mas uma imagem que inseri na planilha e indicando uma célula qualquer como referência. Fiz como indicado, mas não funciona (Só para verificação, fiz com uma célula e deu certo). Há alguma modificação a ser feita na macro?
This comment was minimized by the moderator on the site
Hello
This is very handy, thank you, however this only works if you are in the cell $B$8. I want to create the same hyperlink, which performs the same macro function, but in every row down the sheet.
ie. I have two tabs, sheet 1 and sheet 2. The user is in Sheet 1, and a macro is run which enters data in sheet 1 and sheet 2 on a row-by-row basis. This works fine, but then i want a macro so that the user can click a link in the next cell and it takes them back to their original row in sheet 1, offset a few cells. I can do this using the above, BUT only if the user is in a set row in sheet 2 (eg $B$8). How can i make it so the macro works when they are in sheet 2 B9, B10, B11....?
This comment was minimized by the moderator on the site
This will assign sheet1 column J, row 2 to 35 with a hyperlink to it's own cell with the text name

Sub whateverName()
For i = 2 To 35 Step 1
ActiveCell.FormulaR1C1 = "name"
Range("J" & i).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'sheet1'!J" & i, TextToDisplay:="name"
Next

End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations