使用vba翻译文本 [英] Translate text using vba

查看:450
本文介绍了使用vba翻译文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是一个罕见的请愿书,但这里是问题。

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

我正在调整我的组织中第三方的优势。 excel是用英文开发的,我组织的人只是说西班牙语。我想使用与原始工作表完全相同的代码,我更喜欢不要触摸它(尽管我可以这样做),所以我想使用一个函数,每当msgbox出现(与英文文本) ,我翻译msgbox消息,但不触摸原始脚本。我正在寻找一个可以在原始代码中调用msgbox的每个掩码。

I am adapting an excel of a third-party to my organization. The excel is developed in english and the people of my organization just speaks spanish. I want to use exactly the same code that the original worksheet have, I prefer don't touch it (althought I can do it), so I want to use a function that every time that a msgbox appears (with the text in english), I translate the msgbox messages but without touching the original script. I am looking for a mask that could be called everytime that a msgbox is invoked in the original code.

我希望不要触摸原始代码,因为第三方开发人员可以频繁更改它,每次更改代码可能会非常烦人,小变化

I prefer don't touch the original code because the third-party developer could change it frequently, and it could be very annoying to change the code everytime that they do any little change.

可以吗?

推荐答案

你去。

  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, "</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_using_vba = result_data


End Function

这篇关于使用vba翻译文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆