I'm currently using Microsoft Document Translator in translating my texts. Is it possible to auto translate it using VBA Macro?
我目前正在使用微软文档翻译软件翻译我的文本。是否可以使用VBA宏进行自动翻译?
Thanks.
谢谢。
1 个解决方案
#1
1
I was trying to solve similar issue and found code somewhere implemented it to suit my needs hope it helps you too.
我正在尝试解决类似的问题,并在某个地方找到了实现它的代码,以满足我的需要,希望它也能帮助您。
Sub runner()
Dim conversion As String
conversion = "hello world"
MsgBox translate(conversion)
End Sub
Function translate(text As String)
' Tools Refrence Select Microsoft internet Control
Dim IE As Object, i As Long
Dim inputstring As String, outputstring As String, text As String, result_data As String, CLEAN_DATA
Set IE = CreateObject("InternetExplorer.application")
'choose input language automatic recognition in example
inputstring = "auto"
'choose output language czech in example
outputstring = "cs"
'open google translate
IE.Visible = False
IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text
Do Until IE.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:1"))
Do Until IE.ReadyState = 4
DoEvents
Loop
CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<")
For j = LBound(CLEAN_DATA) To UBound(CLEAN_DATA)
result_data = result_data & Right(CLEAN_DATA(j), Len(CLEAN_DATA(j)) - InStr(CLEAN_DATA(j), ">"))
Next
IE.Quit
transalte = result_data
End Function
#1
1
I was trying to solve similar issue and found code somewhere implemented it to suit my needs hope it helps you too.
我正在尝试解决类似的问题,并在某个地方找到了实现它的代码,以满足我的需要,希望它也能帮助您。
Sub runner()
Dim conversion As String
conversion = "hello world"
MsgBox translate(conversion)
End Sub
Function translate(text As String)
' Tools Refrence Select Microsoft internet Control
Dim IE As Object, i As Long
Dim inputstring As String, outputstring As String, text As String, result_data As String, CLEAN_DATA
Set IE = CreateObject("InternetExplorer.application")
'choose input language automatic recognition in example
inputstring = "auto"
'choose output language czech in example
outputstring = "cs"
'open google translate
IE.Visible = False
IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text
Do Until IE.ReadyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:1"))
Do Until IE.ReadyState = 4
DoEvents
Loop
CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<")
For j = LBound(CLEAN_DATA) To UBound(CLEAN_DATA)
result_data = result_data & Right(CLEAN_DATA(j), Len(CLEAN_DATA(j)) - InStr(CLEAN_DATA(j), ">"))
Next
IE.Quit
transalte = result_data
End Function