Hello, I am looking for a macro which will translate text from French to english. In my excel, text is available from B6 to down and I need translated text from C6 to down. I am using Excel 2016. So can some one help me.
I was using below macro but recently it is throwing error that "unable to get the webservice property of the worksheet function class".
So can some one help me to fix this error. Or Help me with another code.
Function Translate$(sText$, FromLang$, ToLang$)
Dim p1&, p2&, url$, resp$
Const DIV_RESULT$ = "<div class=""result-container"">"
Const URL_TEMPLATE$ = "https://translate.google.com/m?hl=[from]&sl=[from]&tl=[to]&ie=UTF-8&prev=_m&q="
url = URL_TEMPLATE & WorksheetFunction.EncodeURL(sText)
url = Replace(url, "[to]", ToLang)
url = Replace(url, "[from]", FromLang)
resp = WorksheetFunction.WebService(url)
p1 = InStr(resp, DIV_RESULT)
If p1 Then
p1 = p1 + Len(DIV_RESULT)
p2 = InStr(p1, resp, "</div>")
Translate = Mid$(resp, p1, p2 - p1)
End If
End Function
Sub trans_click()
Dim finrow As Integer
Dim frstring, engstring As String
finrow = Sheets("Input").Cells(Rows.Count, 2).End(xlUp).Row
Sheets("Input").Range("C6").End(xlDown).Clear
For i = 6 To finrow
frstring = Sheets("Input").Cells(i, 2)
engstring = Translate(Sheets("Input").Cells(i, 2), "fr", "en")
Sheets("Input").Cells(i, 3) = engstring
Next i
MsgBox ("Translation completed!!")
End Sub
Bookmarks