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

VBA Macro - Auto translations of my text in Excel

我目前正在使用 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