I got an email asking how to translate text to another language using Excel. I don’t know, but it sounds like a fun project.
Function Translate(sWord As String, sFrLang As String, sToLang As String) As String
Dim oIE As Object
Dim sUrl As String
Dim sAllLang As String
sAllLang = "en,es,fr,de,it,pt,"
If InStr(1, sAllLang, sFrLang & ",") > 0 And _
InStr(1, sAllLang, sToLang & ",") > 0 Then
'Create template URL
sUrl = "http://www.systranlinks.com/systran/cgi""
sUrl = sUrl & "AID=5338060&PID=1143024&partner=systran-AffiliatesBox"
sUrl = sUrl & "-en&urltext=#WORD#&y=9&lp=#LANGFR#_#LANGTO#&x=18"
'Replace place holders with arguments
sUrl = Replace(sUrl, "#WORD#", sWord)
sUrl = Replace(sUrl, "#LANGTO#", sToLang)
sUrl = Replace(sUrl, "#LANGFR#", sFrLang)
'Create IE object and navigate to site
Set oIE = CreateObject("InternetExplorer.Application")
'Wait until site is fully loaded
Loop Until oIE.ReadyState = 4 'READYSTATE_COMPLETE
'retrieve translated word
Translate = oIE.Document.all.Item(184).innertext
Translate = CVErr(2015)
If you couldn’t tell by looking at it, this function is super slow. And for some reason it appears to be volatile, that is, it recalculates even when none of its arguments change.
Whenever I automate IE, I use the MSDN Library to get the objects, etc. By the way, the 184 (index for the DocElement) was pure trial and error. I just looped through all the tables on the website and printed the index number and innertext until I saw what I was looking for. Using a word I knew, of course. If they ever change their website, this function will be worthless. I could still loop through the tables, but the function is slow enough as it is.
Here’s what the results look like