Thanks
M
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----------------
--
Regards,
Jake Marx
MS MVP - Excel
www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]
'-2147483638 (8000000a) The data necessary to complete
this operation is not yet available.'
Could this be due to our wonderful firewall that prohibits
Excel Web Queries? Aside from those pesky network folk,
thanks again for the great help.
M
>.
>
I don't think it's due to your firewall - I'd be very surprised if this type
of traffic was being blocked or otherwise restricted. It's using standard
HTTP POST requests, which all takes place on TCP port 80. If the firewall
were blocking this port, you'd have no access to the web.
It works fine on my machine, but maybe you need to check the state of the
request before trying to get the results. Add these 3 lines of code after
invoking the send method and before you request the responseText property:
Do While .readyState <> 4
DoEvents
Loop
That should help - let us know if it doesn't.
>.
>