after copying module sheet and macro's, getting a fault code

DB73

Board Regular
Joined
Jun 7, 2022
Messages
102
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2010
  6. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
Hi all,

i found an excel file on the www what i can use for my master file.
the file that i found is a distance calculator via google maps.
it is working and i got the API key.

the problem is, as i copied everything to my masterfile it gives the following fault:

Compile error: Undefind variable
VBA Code:
Function gDist(strOrig, strDest, strAPI, strMode, strReg)


Dim strURL As String
Dim objHttp As MSXML2.XMLHTTP60
Dim objDom As DOMDocument60
Dim aryDest() As String

If Len(strReg) > 0 Then
    strRegURL = "&region=" & strReg
End If

strURL = "https://maps.googleapis.com/maps/api/distancematrix/xml?units=imperial" & _
        "&origins=" & strOrig & _
        "&destinations=" & strDest & _
        "&traffic_mode1=optimistic" & _
        "&mode=" & strMode & _
        strRegURL & _
        "&key=" & strAPI

Set objHttp = MSXML2.XMLHTTP60

With objHttp
    .Open "GET", strURL, False
    .setRequestHeader "Content-Type", "application/x-www-form-URLEncoded"
    .Send
End With
Set objDom = New DOMDocument60
objDom.LoadXML (objHttp.responseText)

someting wrong in;

VBA Code:
MSXML2.XMLHTTP60
it doesnt seem to work after copying everything
also, i dont know what the "MSXML2.XMLHTTP60" is/means.

someone an idea

tx in advance
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
In the VBA editor, click Tools -> References and select (tick) "Microsoft XML, v6.0" and click OK to close the References dialogue.
 
Upvote 0
Solution
Knipsel.JPG

its on but it doesnt seems to work.
 
Upvote 0
sorry...its works....did someting wrong with the copy paste.
did what u said, and it works..

thanks
 
Upvote 0
I think you also need to change:
VBA Code:
Set objHttp = MSXML2.XMLHTTP60
to:
VBA Code:
Set objHttp = New MSXML2.XMLHTTP60
 
Upvote 0
I think you also need to change:
VBA Code:
Set objHttp = MSXML2.XMLHTTP60
to:
VBA Code:
Set objHttp = New MSXML2.XMLHTTP60
i tried that one also, that didnt work....solution as above works for me.

thanks anyway
 
Upvote 0
I think you also need to change:
VBA Code:
Set objHttp = MSXML2.XMLHTTP60
to:
VBA Code:
Set objHttp = New MSXML2.XMLHTTP60
why should i if it work now ?...get me in trouble in the future with the old code?
 
Upvote 0

Forum statistics

Threads
1,215,761
Messages
6,126,735
Members
449,334
Latest member
moses007

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top