VBA Code:
Public Sub Test1()
' From english to Arab
For i = 1 To 2
Cells(i, 2) = Translate_Text(Cells(i, 1), "en", "ar")
Next
End Sub
Public Sub Test2()
' From Arab to english
For i = 1 To 2
Cells(i, 2) = Translate_Text(Cells(i, 1), "ar", "en")
Next
End Sub
Function Translate_Text(txt_to_conv As String, Optional str_from As String, Optional str_to As String) As String
'Variable declaration
Dim IE As Object, i As Long
Dim Doc As Object
Dim inputstring As String
Dim outputstring As String
Dim text_to_convert As String
Dim result_data As String
Dim str_Data As Variant
'Create instance of IE
Set IE = CreateObject("InternetExplorer.application")
Set Doc = CreateObject("htmlfile")
Set Doc = IE.document' err
inputstring = str_from
'Output language
outputstring = str_to
'Text to be converted
text_to_convert = txt_to_conv
'Open website
IE.Visible = False
IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert
Do Until IE.ReadyState = 4
DoEvents
Loop
'Pause the code for 5 seconds
Application.Wait (Now + TimeValue("0:00:5"))
Do Until IE.ReadyState = 4
DoEvents
Loop
result_data = Doc .getElementsByid("myList").innerHTML
'or
result_data = IE.document.getElementsByid("myList").innerHTML
'result_data = IE.document.IHTMLDocument3_getElementById("myList").innerHTML
str_Data = Split(WorksheetFunction.Substitute(result_data, "</SPAN>", ""), "<")
result_data = vbNullString
For j = LBound(str_Data) To UBound(str_Data)
result_data = result_data & Right(str_Data(j), Len(str_Data(j)) - InStr(str_Data(j), ">"))
Next
'Close IE
IE.Quit
Set IE = Nothing
Translate_Text = result_data
End Function