Translate text using vba

后端 未结 5 1162
既然无缘
既然无缘 2020-11-29 07:08

Probably could be a rare petition, but here is the issue.

I am adapting an excel of a third-party to my organization. The excel is developed in English and the peop

5条回答
  •  渐次进展
    2020-11-29 07:30

    Here you go.

      Sub test()
        Dim s As String
        s = "hello world"
        MsgBox transalte_using_vba(s)
    
    End Sub
    


     Function transalte_using_vba(str) As String
    ' Tools Refrence Select Microsoft internet Control
    
    
        Dim IE As Object, i As Long
        Dim inputstring As String, outputstring As String, text_to_convert As String, result_data As String, CLEAN_DATA
    
        Set IE = CreateObject("InternetExplorer.application")
        '   TO CHOOSE INPUT LANGUAGE
    
        inputstring = "auto"
    
        '   TO CHOOSE OUTPUT LANGUAGE
    
        outputstring = "es"
    
        text_to_convert = str
    
        'open website
    
        IE.Visible = False
        IE.navigate "http://translate.google.com/#" & inputstring & "/" & outputstring & "/" & text_to_convert
    
        Do Until IE.ReadyState = 4
            DoEvents
        Loop
    
        Application.Wait (Now + TimeValue("0:00:5"))
    
        Do Until IE.ReadyState = 4
            DoEvents
        Loop
    
        CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "", ""), "<")
    
        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_using_vba = result_data
    
    
    End Function
    

提交回复
热议问题