2014-11-25 127 views
0

我是這裏的新手,有一個非常簡單的問題。我在Excel中有一些經緯度數據,我想要將其轉換爲Google Maps Street View超鏈接。我在這裏查看了另一個關於如何將超鏈接放在一起的線程,但我正在努力研究如何重複地將緯度/長度數據複製到網址的中間。Excel VBA:從超鏈接內的單元格插入文本

我已級聯我的緯度/經度(小數)插入在正確的格式文本的單電池(即緯度,經度),這是在列J和希望該超鏈接在列N,其中應閱讀:

http://maps.google.com/?cbll= {緯度,經度從J列} & CBP = 12,90,,0,5 &層= C

我試圖尋找一些其他的線程在這裏,但不能完全解決它因爲它們都是相當複雜的例子。希望有人能幫助我輕鬆解決這個問題!謝謝:)

回答

0

考慮:

Sub dural() 
    Dim s1 As String, s2 As String, s3 As String, s4 As String 
    s1 = "http://maps.google.com/?cbll={" 
    s3 = "}&cbp=12,90,,0,5&layer=c" 
    s2 = Range("J1").Text 
    s4 = s1 & s2 & s3 
    With ActiveSheet 
     .Hyperlinks.Add Anchor:=Range("N1"), Address:=s4, TextToDisplay:=s2 
    End With 
End Sub 

所以,如果J1包含:

51.507351.,-0.127758 

N1其結果將是:

http://maps.google.com/?cbll= {51.507351, - 。 0.127758} & cbp = 12,90,,0.5 & layer = c

編輯#1:

要運行這個落筆列Ĵ,使用這個版本:

Sub dural2() 
    Dim s1 As String, s2 As String, s3 As String, s4 As String 
    Dim N As Long, i As Long 
    N = Cells(Rows.Count, "J").End(xlUp).Row 
    s1 = "http://maps.google.com/?cbll={" 
    s3 = "}&cbp=12,90,,0,5&layer=c" 
    For i = 1 To N 
     s2 = Range("J" & i).Text 
     s4 = s1 & s2 & s3 
     With ActiveSheet 
      .Hyperlinks.Add Anchor:=Range("N" & i), Address:=s4, TextToDisplay:=s2 
     End With 
    Next i 
End Sub 
+0

非常好,謝謝! 你能告訴我如何在300多行中重複這個嗎?我嘗試將「J1」更改爲「J1:J300」,但它不喜歡它。 – 2014-11-25 14:31:24

+0

看我的**編輯#1 ** – 2014-11-25 14:43:16

+0

就是這樣!謝謝! – 2014-11-25 14:53:10

相關問題