
我正在嘗試建立一個儲存格,該儲存格將根據另一個 Excel 儲存格中填寫的內容拉入超連結。我的超連結部分可以正常工作,但我希望為超連結提供一個比用於獲取網頁的 ID 或整個網址更好的標籤。我認為嘗試拉入網頁標題是最簡單的。這可能嗎?
也許為了提供一點幫助,我目前正在使用此功能來提取網址
=IF(LEN(Excel Cell Value)>0,HYPERLINK(CONCATENATE("First part of the web address",(Excel Cell Value),"Second part of the web address"),Excel Cell Value),"")
答案1
=IF(LEN(Excel Cell Value)>0,HYPERLINK(CONCATENATE("First part of the web address",(Excel Cell Value),"Second part of the web address"),Excel Cell Value),"")
我不明白這一點。讓我試著分解它 -
If(Len(cell value)>0) - if the cell isn't empty, do TRUE
TRUE - Hyperlink(Concatenate(first, (cell value), second), (cell value)
FALSE - ""
現在讓我們看看超連結是如何運作的
Hyperlink(link location, friendly name)
對你來說這是
link location = concatenate(first, value, second)
friendly name = value
您正在將友善名稱指定為儲存格值。所以,除非你有類似的東西 -
A1 = Google
A2 = Hyperlink(Concatenate("https://www.",A1,".com",A1))
A2=Google
這行不通。您唯一能做的就是使用 VBA 進入頁面並收集信息,或者使用類似 -
A1 = Google
A2 = Searching Website
A3 = Hyperlink(Concatenate("https://www.",A1,".com",A2))
A3=搜尋網站
透過 VBA 取得標題 -
Sub gettitle()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate "http://superuser.com/"
While ie.busy
DoEvents
Wend
Dim title As String
title = ie.document.title
MsgBox (title)
End Sub
好的,要使函數返回帶有標題的超鏈接,您需要一個用戶定義函數 (UDF) -
Function GetTitle(site As Range) As String
Dim title As String
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate site
While ie.busy
DoEvents
Wend
title = ie.document.title
ie.Quit
GetTitle = title
End Function
這將轉到網頁目標並返回標題。現在,假設您的單元格中有一個網頁A1
- 現在您需要調用標題函數 -
A2 = GetTitle(A1)
A3 = Hyperlink(A1,A2)