Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

time ago I used this[^] Excel macro to translate texts in an Excel document automatically.

It worked like charm, but now I can't get it to work... all the magic happens here:

VB
Dim strUrl As String
Dim strResult As String

On Error GoTo ErrHandler:

strText = Replace$(strText, Chr$(32), "%20")
strText = Replace$(strText, Chr$(160), "%20")

strUrl = "http://translate.google.com/translate_a/t?client=t&text={S}&hl=en&sl={F}&tl={T}&multires=1&pc=0&rom=1&sc=1"
strUrl = Replace$(strUrl, "{S}", strText)
strUrl = Replace$(strUrl, "{F}", Split(strSHORTCODES, ",")(eFrom))
strUrl = Replace$(strUrl, "{T}", Split(strSHORTCODES, ",")(eTo))

Dim oHttp As Object
Set oHttp = CreateObject("MSXML2.XMLHTTP")
oHttp.Open "GET", strUrl, False
oHttp.Send '<== HERE IS WHERE IT STOPS
If oHttp.Status = 200 Then
   strResult = Replace$(Mid$(CStr(Split(strResult, ",")(0)), 4), Chr$(34), "")
Else
   strResult = "FAILED!"
End If
Set oHttp = Nothing

Translate = strResult

ErrHandler:
  MsgBox(Err.Description)


I can't get it to work now... the macro is executed and I can see how the code reaches the SEND call but it simply disappears here...

I've added a Error handler and I can see that the message that appears is "DENIED ACCESS".

Any idea on why it is happening?

Even I don't think this has something to do... The last time I executed this macro I was using windows 8.1 and now I'm using windows 7.

I can imagine the error coming from a new Google policy, from my new installation...

Any hint?

Thank you all!
Posted

You want to perform a GET request, so you should use Open instead of Send. Check the link for more info.

https://msdn.microsoft.com/en-us/library/ms536648(v=vs.85).aspx[^]

Good luck!
 
Share this answer
 
Comments
Joan M 27-May-15 15:01pm    
That's for sure not correct, that code did worked before and perfectly, the issue is that Google has shut the free service down, therefore the DENIED ACCESS...

Anyway, thank you for posting!
E.F. Nijboer 27-May-15 15:45pm    
I'm sorry. Must have looked at the wrong component. Luckily you did find your answer :-)
Quote:
UPDATE: Google is shutting down the free Translation API on which this solution depends. Instead, they have published a new paid API that you can access with our new translation add-in. Though it's not free, it's not expensive either, and it's much faster and more reliable than the old free solution. There's a free trial so you can test before purchasing.


So this can be read as That's all folks!

I'll try to get it done using Microsoft translation tool.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900