How to debug a macro that calculates distances between two points?
I have a macro that calculates distances between two points. I am unable to get it to work, and would like some help debugging it.
I have created a Google API key, and have incorporated that in as well, but for some reason the macro doesn't work
Public Function
GetDT(origin_city As String, _
origin_state As String, origin_country As String, _
destination_city As String, _
destination_state As String, destination_country As String _
)
Dim surl As String
Dim oXH As Object
Dim bodytxt As String
Dim distanc_e As String
surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins="
& _
Replace(origin_city, " ", "+") & "+" & Replace(origin_state, " ", "+") &
"+" & Replace(origin_country, " ", "+") & _
"&destinations=" & _
Replace(destination_city, " ", "+") & "+" & Replace(destination_state, "
", "+") & "+" & Replace(destination_country, " ", "+") & _
"&mode=driving&units=metric&key=MY_KEY"
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", surl, False
.send
bodytxt = .responseText
End With
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
GetDT = distanc_e
Set oXH = Nothing
End Function
vba google-api xmlhttprequest
add a comment |
I have a macro that calculates distances between two points. I am unable to get it to work, and would like some help debugging it.
I have created a Google API key, and have incorporated that in as well, but for some reason the macro doesn't work
Public Function
GetDT(origin_city As String, _
origin_state As String, origin_country As String, _
destination_city As String, _
destination_state As String, destination_country As String _
)
Dim surl As String
Dim oXH As Object
Dim bodytxt As String
Dim distanc_e As String
surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins="
& _
Replace(origin_city, " ", "+") & "+" & Replace(origin_state, " ", "+") &
"+" & Replace(origin_country, " ", "+") & _
"&destinations=" & _
Replace(destination_city, " ", "+") & "+" & Replace(destination_state, "
", "+") & "+" & Replace(destination_country, " ", "+") & _
"&mode=driving&units=metric&key=MY_KEY"
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", surl, False
.send
bodytxt = .responseText
End With
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
GetDT = distanc_e
Set oXH = Nothing
End Function
vba google-api xmlhttprequest
2
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I thinkSet oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.
– Darren Bartrup-Cook
Nov 28 '18 at 9:35
add a comment |
I have a macro that calculates distances between two points. I am unable to get it to work, and would like some help debugging it.
I have created a Google API key, and have incorporated that in as well, but for some reason the macro doesn't work
Public Function
GetDT(origin_city As String, _
origin_state As String, origin_country As String, _
destination_city As String, _
destination_state As String, destination_country As String _
)
Dim surl As String
Dim oXH As Object
Dim bodytxt As String
Dim distanc_e As String
surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins="
& _
Replace(origin_city, " ", "+") & "+" & Replace(origin_state, " ", "+") &
"+" & Replace(origin_country, " ", "+") & _
"&destinations=" & _
Replace(destination_city, " ", "+") & "+" & Replace(destination_state, "
", "+") & "+" & Replace(destination_country, " ", "+") & _
"&mode=driving&units=metric&key=MY_KEY"
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", surl, False
.send
bodytxt = .responseText
End With
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
GetDT = distanc_e
Set oXH = Nothing
End Function
vba google-api xmlhttprequest
I have a macro that calculates distances between two points. I am unable to get it to work, and would like some help debugging it.
I have created a Google API key, and have incorporated that in as well, but for some reason the macro doesn't work
Public Function
GetDT(origin_city As String, _
origin_state As String, origin_country As String, _
destination_city As String, _
destination_state As String, destination_country As String _
)
Dim surl As String
Dim oXH As Object
Dim bodytxt As String
Dim distanc_e As String
surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins="
& _
Replace(origin_city, " ", "+") & "+" & Replace(origin_state, " ", "+") &
"+" & Replace(origin_country, " ", "+") & _
"&destinations=" & _
Replace(destination_city, " ", "+") & "+" & Replace(destination_state, "
", "+") & "+" & Replace(destination_country, " ", "+") & _
"&mode=driving&units=metric&key=MY_KEY"
Set oXH = CreateObject("msxml2.xmlhttp")
With oXH
.Open "get", surl, False
.send
bodytxt = .responseText
End With
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5)
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1)
GetDT = distanc_e
Set oXH = Nothing
End Function
vba google-api xmlhttprequest
vba google-api xmlhttprequest
edited Nov 27 '18 at 20:10
halfer
14.6k758113
14.6k758113
asked Nov 27 '18 at 7:31
VarunVarun
1
1
2
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I thinkSet oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.
– Darren Bartrup-Cook
Nov 28 '18 at 9:35
add a comment |
2
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I thinkSet oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.
– Darren Bartrup-Cook
Nov 28 '18 at 9:35
2
2
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I think
Set oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.– Darren Bartrup-Cook
Nov 28 '18 at 9:35
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I think
Set oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.– Darren Bartrup-Cook
Nov 28 '18 at 9:35
add a comment |
1 Answer
1
active
oldest
votes
There is no way to confidently answer this question with the information provided. Writing a separate function to create the url will make your code more testable. Using Option Explicit
to force all variables to be declared will detect any typos.
If MY_KEY
is a variable then the url should look like this "..metric&key=" & MY_KEY
.
surl = GetDTURL(origin_city, origin_state, origin_country, destination_city, destination_state, destination_country)
Function GetDTURL(origin_city As String, origin_state As String, origin_country As String, destination_city As String, destination_state As String, destination_country As String)
Dim surl As String
Const BaseURl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=@origin_city+@origin_state+@origin_country&destinations=@destination_city+@destination_state+@destination_country&mode=driving&units=metric&key=MY_KEY"
surl = BaseURl
surl = Replace(surl, "@origin_city", origin_city)
surl = Replace(surl, "@origin_state", origin_state)
surl = Replace(surl, "@origin_country", origin_country)
surl = Replace(surl, "@destination_city", destination_city)
surl = Replace(surl, "@destination_state", destination_state)
surl = Replace(surl, "@destination_country", destination_country)
surl = Replace(surl, " ", "+")
GetDTURL = surl
End Function
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
|
show 5 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494728%2fhow-to-debug-a-macro-that-calculates-distances-between-two-points%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is no way to confidently answer this question with the information provided. Writing a separate function to create the url will make your code more testable. Using Option Explicit
to force all variables to be declared will detect any typos.
If MY_KEY
is a variable then the url should look like this "..metric&key=" & MY_KEY
.
surl = GetDTURL(origin_city, origin_state, origin_country, destination_city, destination_state, destination_country)
Function GetDTURL(origin_city As String, origin_state As String, origin_country As String, destination_city As String, destination_state As String, destination_country As String)
Dim surl As String
Const BaseURl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=@origin_city+@origin_state+@origin_country&destinations=@destination_city+@destination_state+@destination_country&mode=driving&units=metric&key=MY_KEY"
surl = BaseURl
surl = Replace(surl, "@origin_city", origin_city)
surl = Replace(surl, "@origin_state", origin_state)
surl = Replace(surl, "@origin_country", origin_country)
surl = Replace(surl, "@destination_city", destination_city)
surl = Replace(surl, "@destination_state", destination_state)
surl = Replace(surl, "@destination_country", destination_country)
surl = Replace(surl, " ", "+")
GetDTURL = surl
End Function
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
|
show 5 more comments
There is no way to confidently answer this question with the information provided. Writing a separate function to create the url will make your code more testable. Using Option Explicit
to force all variables to be declared will detect any typos.
If MY_KEY
is a variable then the url should look like this "..metric&key=" & MY_KEY
.
surl = GetDTURL(origin_city, origin_state, origin_country, destination_city, destination_state, destination_country)
Function GetDTURL(origin_city As String, origin_state As String, origin_country As String, destination_city As String, destination_state As String, destination_country As String)
Dim surl As String
Const BaseURl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=@origin_city+@origin_state+@origin_country&destinations=@destination_city+@destination_state+@destination_country&mode=driving&units=metric&key=MY_KEY"
surl = BaseURl
surl = Replace(surl, "@origin_city", origin_city)
surl = Replace(surl, "@origin_state", origin_state)
surl = Replace(surl, "@origin_country", origin_country)
surl = Replace(surl, "@destination_city", destination_city)
surl = Replace(surl, "@destination_state", destination_state)
surl = Replace(surl, "@destination_country", destination_country)
surl = Replace(surl, " ", "+")
GetDTURL = surl
End Function
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
|
show 5 more comments
There is no way to confidently answer this question with the information provided. Writing a separate function to create the url will make your code more testable. Using Option Explicit
to force all variables to be declared will detect any typos.
If MY_KEY
is a variable then the url should look like this "..metric&key=" & MY_KEY
.
surl = GetDTURL(origin_city, origin_state, origin_country, destination_city, destination_state, destination_country)
Function GetDTURL(origin_city As String, origin_state As String, origin_country As String, destination_city As String, destination_state As String, destination_country As String)
Dim surl As String
Const BaseURl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=@origin_city+@origin_state+@origin_country&destinations=@destination_city+@destination_state+@destination_country&mode=driving&units=metric&key=MY_KEY"
surl = BaseURl
surl = Replace(surl, "@origin_city", origin_city)
surl = Replace(surl, "@origin_state", origin_state)
surl = Replace(surl, "@origin_country", origin_country)
surl = Replace(surl, "@destination_city", destination_city)
surl = Replace(surl, "@destination_state", destination_state)
surl = Replace(surl, "@destination_country", destination_country)
surl = Replace(surl, " ", "+")
GetDTURL = surl
End Function
There is no way to confidently answer this question with the information provided. Writing a separate function to create the url will make your code more testable. Using Option Explicit
to force all variables to be declared will detect any typos.
If MY_KEY
is a variable then the url should look like this "..metric&key=" & MY_KEY
.
surl = GetDTURL(origin_city, origin_state, origin_country, destination_city, destination_state, destination_country)
Function GetDTURL(origin_city As String, origin_state As String, origin_country As String, destination_city As String, destination_state As String, destination_country As String)
Dim surl As String
Const BaseURl As String = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=@origin_city+@origin_state+@origin_country&destinations=@destination_city+@destination_state+@destination_country&mode=driving&units=metric&key=MY_KEY"
surl = BaseURl
surl = Replace(surl, "@origin_city", origin_city)
surl = Replace(surl, "@origin_state", origin_state)
surl = Replace(surl, "@origin_country", origin_country)
surl = Replace(surl, "@destination_city", destination_city)
surl = Replace(surl, "@destination_state", destination_state)
surl = Replace(surl, "@destination_country", destination_country)
surl = Replace(surl, " ", "+")
GetDTURL = surl
End Function
edited Nov 27 '18 at 8:40
answered Nov 27 '18 at 7:50
TinManTinMan
2,221212
2,221212
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
|
show 5 more comments
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
Thanks @TinMan for taking the effort here.....1)MY_KEY is my API Key that i haven't pasted here........2) For this line of your code- (surl = Replace(" ", "+")), I got an error message - Compile error: Argument not optional.....Could you further help me>?
– Varun
Nov 27 '18 at 8:36
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
@Varun thanks. I updated my code. I should have tested the function.
– TinMan
Nov 27 '18 at 8:41
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
I am not getting the value of the distance, but this text : maps.googleapis.com/maps/api/distancematrix/…SyCF0*EdJoy*****GZ2********tZQw......Could you help me again? Thanks a ton:)
– Varun
Nov 27 '18 at 10:20
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
@Varun: the link you have provided here has corrupted, as is evident from your comment. Remember also that this maps endpoint may not show readers what it shows you, and it may also change over time. Ergo, it is necessary for you to explain what it shows and what is wrong with it. That information is probably best added to your question, at the end.
– halfer
Nov 27 '18 at 20:12
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
Thanks, I should have been more clear. The text message "maps.googleapis.com/maps/api/distancem......." that you checked was an Excel output for the code written by @TinMan. The link is not corrupted, I changed the key as I wanted to keep it confidential. The purpose was to show that a link gets generated instead of a distance value being populated. Copying the link on my web page gives an accurate value of distance. It would be great if the value gets populated on an Excel interface directly, could you or TinMan modify the code written by him to make this happen? Thanks again
– Varun
Nov 28 '18 at 9:32
|
show 5 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494728%2fhow-to-debug-a-macro-that-calculates-distances-between-two-points%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
When you say it doesn't work... what does it do instead of working? Does it give a message, does the parent app crash, does it beep loudly and spew smoke out the back?
– Darren Bartrup-Cook
Nov 27 '18 at 10:51
Gives a #VALUE! error (On the excel interface when i write the formula GetDT(......), not on the VBA interface), instead of the value of the distance between 2 points
– Varun
Nov 28 '18 at 9:14
So when run as a function within the VBA environment it returns the correct value, but when entered as a worksheet function it doesn't work - there's a lot of limitations when using a UDF. I think
Set oXH = CreateObject("msxml2.xmlhttp")
may come under that, but I'm not sure.– Darren Bartrup-Cook
Nov 28 '18 at 9:35