我尝试使用宏来获取关键字中的前3个街道地址,然后让用户选择一个。但是,我一直遇到错误13(不匹配的数据类型)我的案例1"声明或在最后一个输入框中。有什么帮助吗?我对VBA来说比较新。
datastore.manager
答案 0 :(得分:0)
这最终对我有用。谢谢:))
Sub allowUserToChooseLocation()
Dim xhrRequest As XMLHTTP60
Dim domDoc As DOMDocument60
Dim query As String
Dim myNodes As IXMLDOMNodeList
Dim myNode As IXMLDOMNode
Dim nNode As Integer
Dim re As Range
Dim result(0 To 2) As String
'allows user to select range
Set myValue = Application.InputBox(prompt:="Please select the list of addresses wether empty or not of the organizations", Type:=8)
Set myValueCol = Application.InputBox(prompt:="Please select the column with the names", Type:=8)
For Each re In myValue
If IsEmpty(re.Value) Or re.Value = vbNullString Then
query = Cells(re.Row, myValueCol.Column)
query = Replace(query, " ", "+")
query = Replace(query, ",", "%2C")
'You must acquire a google api key and enter it here
Dim googleKey As String
googleKey = "Key_Here" 'your api key here
'Send a "GET" request for place/textsearch
Set xhrRequest = New XMLHTTP60
xhrRequest.Open“GET”,“https://maps.googleapis.com/maps/api/place/textsearch/xml?query=”&查询& “& key = AIzaSyAmkY6nbeMGS19t0jdcFQT_SxoFcm7LUdE”,错误 xhrRequest.send
'Save the response into a document
Set domDoc = New DOMDocument60
domDoc.LoadXML xhrRequest.responseText
Set myNodes = domDoc.SelectNodes("//result/formatted_address")
For nNode = 0 To 2
Set myNode = myNodes(nNode)
If Not (myNode Is Nothing) Then
result(nNode) = myNode.nodeTypedValue
End If
If (myNode Is Nothing) Then
result(nNode) = "No additonal addresses found"
End If
Next nNode
sinput = Application.InputBox(prompt:="1. " & result(0) & vbNewLine & "2. " & result(1) & vbNewLine & "3. " & result(2), Type:=1)
Select Case sinput
Case 1
re.Value = result(0)
Case 2
re.Value = result(1)
Case 3
re.Value = result(2)
End Select
结束如果 下一步
End Sub