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 29 30
| Sub test()
Dim cel As Range
For Each cel In Worksheets("site").Range("A1:A10") ' ("A1:A10") à modifier par ta plage
cel.Value = Translate(urlI:="https://translate.google.pl/m?&sl=ru&tl=fr&ie=UTF-8&prev=_m&q=" & cel.Value)
Next cel
End Sub
Public Function Translate(Optional texte As String, Optional From As String = "en", Optional ToLang As String = "fr", Optional urlI As String)
'PatrickToulon DVP
Dim RQ As Object, URL As String, code As String, elem As Object, x As Long
Set RQ = CreateObject("microsoft.xmlhttp") '"MSXML2.ServerXMLHTTP"
If urlI <> "" Then
URL = urlI
Else
URL = "https://translate.google.pl/m?&sl=" & From & "&tl=" & ToLang & "&ie=UTF-8&prev=_m&q=" & texte
End If
RQ.Open "POST", URL, False
RQ.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
RQ.send
With CreateObject("htmlfile")
.body.innerhtml = RQ.responsetext
Debug.Print Replace(RQ.responsetext, "<>", ">" & vbCrLf & "<")
For Each elem In .ALL
If elem.Tagname = "DIV" And elem.classname = "t0" Then Translate = elem.innerhtml: Exit For
Next
End With
End Function |
Partager