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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Function transalte_using_vba(ByRef str As String, ByRef inputstring As String, ByRef outputstring As String) As String
' Tools Refrence Select Microsoft internet Control
Dim IE As InternetExplorer, i As Long
Dim start
'Dim inputstring As String, outputstring As String,
Dim result_data As String, CLEAN_DATA
Set IE = CreateObject("InternetExplorer.Application")
PrepText = Replace(str, vbCrLf, "%0A") 'Carriage-Return-Linefeed
PrepText = Replace(PrepText, vbCr, "%0A") 'Carriage Return
PrepText = Replace(PrepText, vbLf, "%0A") 'Linefeed
PrepText = Replace(PrepText, "&", "%26")
PrepText = Replace(PrepText, "@", "%40")
PrepText = Replace(PrepText, "#", "%23")
PrepText = Replace(PrepText, "$", "%24")
PrepText = Replace(PrepText, "=", "%3D")
PrepText = Replace(PrepText, "+", "%2B")
PrepText = Replace(PrepText, ";", "%3B")
PrepText = Replace(PrepText, ":", "%3A")
PrepText = Replace(PrepText, ",", "%2C")
PrepText = Replace(PrepText, "/", "%2F")
PrepText = Replace(PrepText, "$", "%24")
PrepText = Replace(PrepText, "?", "%3F")
'open website
'IE.Visible = True
IE.Visible = False
'https://translate.google.com/?hl=fr#en/fr/lopa
IE.navigate ("https://translate.google.com/?hl=" & outputstring & "#" & inputstring & "/" & outputstring & "/" & PrepText)
'Application.Wait (Now + TimeValue("0:00:5"))
start = Timer
Do Until (IE.readyState = READYSTATE_COMPLETE Or Timer > start + 10)
Call SupMessAvertissement
Loop
Application.Wait (Now + TimeValue("0:00:1"))
If IE.readyState <> 4 Then
MsgBox ("Problem of connexion/application process, please try again later.")
Else
CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<")
For j = LBound(CLEAN_DATA) To UBound(CLEAN_DATA)
CLEAN_DATA(j) = Replace(CLEAN_DATA(j), "BR>", vbNewLine)
result_data = result_data & Right(CLEAN_DATA(j), Len(CLEAN_DATA(j)) - InStr(CLEAN_DATA(j), ">"))
Next
IE.Quit
transalte_using_vba = result_data
End If
End Function |
Partager