
Set jsonProvider = CreateObject("MSXML2.ServerXMLHTTP") Private Function GoogleTranslateJ(ByVal text, ByVal resLang, ByVal srcLang) As String If you receive 403 (Daily Limit), you need to add payment method into your Google Cloud Account, then you will get results instantly. To Enable Google Translation API, first you should create the project and credentials. One of the modern solution using Google Translation API URL = "" & langFrom & "/" & langTo & "/" & TextĪutoTranslate = IE.Document.getElementByID("result_box").innerText Public Function AutoTranslate(ByVal Text As String, Optional LanguageFrom As LanguageCode, Optional LanguageTo As LanguageCode2) As Stringĭim langFrom As String, langTo As String, IE As InternetExplorer, URL As String, myArray MsgBox AutoTranslate(msg, InputEnglish, ReturnSpanish)įunction. Keep in mind, there's a character limit of around 3000 or so with google translate, and also, you must set IE=nothing especially if you will be using this multiple times, otherwise you will create multiple IE processes and eventually it won't work anymore. And finally, to get rid of having to clean up the output, I just used. Also, in this sample I selected the Microsoft Internet Controls reference so instead of creating an object, there's an InternetExplorer object used. For simplicity I only included a few language codes. It's function with optional enumeration objects that point to language codes used by google translate. IE.navigate "" & inputstring & "/" & outputstring & "/" & text_to_convertĪpplication.Wait (Now + TimeValue("0:00:5"))ĬLEAN_DATA = Split((IE.Document.getElementById("result_box").innerHTML, "", ""), "")) Set IE = CreateObject("InternetExplorer.application") ' Tools Refrence Select Microsoft internet Controlĭim inputstring As String, outputstring As String, text_to_convert As String, result_data As String, CLEAN_DATA Function translate_using_vba(str) As String
