Jake said:
Beto,
There are a few ways to do this programmatically without using API
functions. One is to use the XMLHTTP object to "screen scrape" the web page
and get the value. Here's a thread with a good example of how to do it:
http://groups.google.com/[email protected]
Hi Jake, I tried the example, but it failed in a compilation error right
here:
Dim xml As XMLHTTP40
I already set "Microsoft XML, v3.0" (version 3 in my case) in
Tools/References of the VBE Editor.
Any ideas of what's wrong?
Regards,
PS: I copied the post you were referring to so you won't need to look
for it again.
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.
------------------------------------------------------------------
[COPIED POST STARTS]
You can post data to a website and grab the response using XMLHTTP. Here's
some sample code that will use the babelfish site to translate a phrase,
then return the translated phrase. In order to get it to work, you need to
set a reference to "Microsoft XML, vX.0" (where in my case, X=4).
'/-------------BEGIN CODE---------------
Public Enum TranslateLanguages
Eng_Fren = 1
Eng_Ger = 2
Eng_Ita = 3
Eng_Port = 4
Eng_Span = 5
Fren_Eng = 6
Fren_Ger = 7
Ger_Eng = 8
Ger_Fren = 9
Ita_Eng = 10
Port_Eng = 11
Span_Eng = 12
End Enum
Public Function gsTranslateText(rsTextToTranslate, _
rMode As TranslateLanguages) As String
Dim xml As XMLHTTP40
Dim abytPostData() As Byte
Dim sMode As String
Dim sResponse As String
Dim nStartPos As Integer
Dim nEndPos As Integer
Select Case rMode
Case Eng_Fren
sMode = "en_fr"
Case Eng_Ger
sMode = "en_de"
Case Eng_Ita
sMode = "en_it"
Case Eng_Port
sMode = "en_pt"
Case Eng_Span
sMode = "en_es"
Case Fren_Eng
sMode = "fr_en"
Case Fren_Ger
sMode = "fr_de"
Case Ger_Eng
sMode = "de_en"
Case Ger_Fren
sMode = "de_fr"
Case Ita_Eng
sMode = "it_en"
Case Port_Eng
sMode = "pt_en"
Case Span_Eng
sMode = "es_en"
End Select
abytPostData = StrConv("doit=done&intl=1" _
& "&tt=urltext&lp=" & sMode & "&urltext=" _
& rsTextToTranslate, vbFromUnicode)
Set xml = New XMLHTTP40
With xml
.Open "POST", _
"
http://babelfish.altavista.com/babelfish/tr"
.setRequestHeader "Content-Type", _
"application/x-www-form-urlencoded"
.send abytPostData
sResponse = .responseText
End With
'/ find translation
nStartPos = InStr(1, sResponse, "lang=" & _
Right$(sMode, 2), vbTextCompare)
If nStartPos Then
nStartPos = nStartPos + 8
nEndPos = InStr(nStartPos, sResponse, _
"</div>", vbTextCompare) - 1
If nEndPos >= nStartPos Then gsTranslateText = _
Mid$(sResponse, nStartPos, nEndPos - _
nStartPos + 1)
End If
Set xml = Nothing
End Function
'/--------------END CODE----------------