Bonjour à tous,
Je cherche à utiliser google translate via Excel et j'utilise le code suivant :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Public Function GoogleTranslate(rng As String, Optional translateFrom As String = "en", Optional translateTo As String = "es")
Dim getParam As String, objHTTP As Object, URL As String
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
getParam = "Hello"
URL = "https://translate.google.pl/m?hl=" & translateFrom & "&sl=" & translateFrom & "&tl=" & translateTo & "&ie=UTF-8&prev=_m&q=" & getParam
Debug.Print URL
With objHTTP
.Open "GET", URL, False
'.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
.Send ("")
Debug.Print (objHTTP.StatusText)
If InStr(.responseText, "<div class=""result-container""") > 0 Then
Application.Wait (Now + TimeValue("0:00:01"))
GoogleTranslate = Clean(RegexExecute(.responseText, "div[^""]*?""result-container"".*?>(.+?)</div>"))
Application.Wait (Now + TimeValue("0:00:01"))
Else
Application.Wait (Now + TimeValue("0:00:01"))
GoogleTranslate = CVErr(xlErrValue)
Application.Wait (Now + TimeValue("0:00:01"))
End If
End With
End Function |
Cela marche parfaitement bien sur mon PC.
Quand j'utilise le meme fichier d'un autre PC cela ne marche pas. J'ai creusé et j'ai vu que la différence se trouvé ici :
Debug.Print (objHTTP.StatusText)
Ce Code me renvoit Forbiden
Comment puis-je changer cela ?
en modifiant le ?
Meric pour votre aide
Partager