I am trying to add a VBA function to my excel sheet were I can translate or convert the names to arabic to stop them in my database. I added the developer tab and open editor and I added the following function but it is not working...Any help please
Function Translate_To_Arabic(str) As String
' Tools Refrence Select Microsoft internet Control
Dim IE As Object, i As Long
Dim inputstring As String, outputstring As String, text_to_convert As String, result_data As String, CLEAN_DATA
Set IE = CreateObject("InternetExplorer.application")
' TO CHOOSE INPUT LANGUAGE
inputstring = "auto"
' TO CHOOSE OUTPUT LANGUAGE
outputstring = "ar"
text_to_convert = str
'open website
IE.Visible = False
IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert
Do Until IE.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:5"))
Do Until IE.ReadyState = 4
DoEvents
Loop
CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<")
For j = LBound(CLEAN_DATA) To UBound(CLEAN_DATA)
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 Function
If You want to use this function as UDF use this code:
you can use this function in your workbook using this formula in B1:
=Translate_To_Arabic(A1)
. now if you typebook
in cell A1 you will seeكتاب
in cell B1. if you want to use this function as add-in see this linkThe problem is that your last line of the code should be:
You have mispeeled "Translate"
Also make sure you added the Reference to the Microsoft Internet Controls