如何在 Excel 中從超連結提取實際地址
Excel 是一款功能強大的工具。您可以使用 Excel 中的 VBA 程式碼從超連結中提取實際地址。透過迴圈遍歷包含超連結的單元格範圍,程式碼檢查每個單元格是否具有超連結,提取地址,刪除任何字首(如“mailto:”或“tel:”),並使用提取的地址更新相鄰單元格。使用此 VBA 解決方案,您可以自動執行從 Excel 中的超連結提取實際地址的過程,從而節省時間和精力。
以下是您可以執行此操作的步驟
步驟 1
開啟您要將 Excel 資料匯出到文字檔案的 Excel 檔案。
按 Alt + F11 以在 Excel 中開啟 Visual Basic 編輯器。
透過點選“插入”並選擇“模組”來插入一個新的模組。
在模組視窗中,貼上以下程式碼
示例
Sub ExtractHyperlinkAddresses() Dim rng As Range Dim cell As Range Dim address As String 'Specify the range containing the hyperlinks Set rng = Range("A2:A6") 'Update with your desired range 'Loop through each cell in the range For Each cell In rng 'Check if the cell contains a hyperlink If cell.Hyperlinks.Count > 0 Then 'Extract the address from the hyperlink address = cell.Hyperlinks(1).Address 'Remove any "mailto:" or "tel:" prefixes address = Replace(address, "mailto:", "") address = Replace(address, "tel:", "") 'Update the cell value with the extracted address cell.Offset(0, 1).Value = address End If Next cell End Sub

步驟 2
使用包含超連結的範圍修改 Set rng = Range("A2:A6") 這行程式碼。這指定了您要提取地址的範圍。
儲存模組並關閉 VBA 編輯器。
步驟 3
按 Alt + F8 開啟宏對話方塊。
從列表中選擇“ExportToTextFile”宏,然後點選“執行”。
步驟 4
在當前工作表中,您可以從超連結中獲取地址,如下所示
結論
要使用 VBA 從 Excel 中的超連結提取實際地址,您可以使用提供的程式碼。它迴圈遍歷指定的範圍,檢查超連結,提取地址,刪除任何字首(如“mailto:”或“tel:”),並更新相鄰單元格。根據需要調整範圍。此 VBA 解決方案使該過程自動化,使其能夠高效地處理大型資料集。請記住開啟 VBA 編輯器,將程式碼插入到新模組中,更新範圍並執行宏。提取的地址將填充到相鄰單元格中,使您可以使用實際地址而不是超連結。
廣告