VBA宏-Excel中文本的自动翻译

VBA宏-Excel中文本的自动翻译,excel,vba,macros,ms-office,translation,Excel,Vba,Macros,Ms Office,Translation,我目前正在使用Microsoft Document Translator翻译我的文本。是否可以使用VBA宏自动翻译 谢谢。我正试图解决类似的问题,并在某处找到了实现它的代码,以满足我的需要,希望它也能帮助您 Sub runner() Dim conversion As String conversion = "hello world" MsgBox translate(conversion) End Sub Function translate(text As Stri

我目前正在使用Microsoft Document Translator翻译我的文本。是否可以使用VBA宏自动翻译


谢谢。

我正试图解决类似的问题,并在某处找到了实现它的代码,以满足我的需要,希望它也能帮助您

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
Sub-runner()
将Dim转换为字符串
conversion=“你好,世界”
MsgBox转换(转换)
端接头
函数转换(文本作为字符串)
'工具参考选择Microsoft internet控件
朦胧如物,我如长
Dim inputstring作为字符串,outputstring作为字符串,text作为字符串,result_数据作为字符串,CLEAN_数据
设置IE=CreateObject(“InternetExplorer.application”)
'在示例中选择输入语言自动识别
inputstring=“自动”
'在示例中选择输出语言捷克语
outputstring=“cs”
“打开谷歌翻译”
可见=假
即“导航”http://translate.google.com/#&inputstring&“/”&outputstring&“/”&text
直到IE.ReadyState=4为止
多芬特
环
Application.Wait(现在+时间值(“0:00:1”))
直到IE.ReadyState=4为止
多芬特
环
CLEAN_DATA=Split(Application.WorksheetFunction.Substitute(即.Document.getElementById(“结果框”).innerHTML,“,”,“),”)
下一个
即退出
transalte=结果\数据
端函数

谢谢,但这不是Microsoft Translator,对吗?如何定义要翻译的语言?我只收到一条空白消息。在输出字符串中将值更改为您的国家/地区代码好的,但我收到一条空白消息。你知道问题出在哪里吗?你所说的微软翻译是什么意思?你是说网上网页?我不知道这个的代码结构。不管怎样,谷歌翻译在翻译方面还是有点好。。