在Excel VBA宏中使用Google翻译 [英] Using Google Translate in a Excel VBA macro

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

问题描述

伙计们....多年来,我在Excel宏之一中使用了以下功能,以帮助我将英语到法语的照片标题组成.这个上午开始引发错误,该错误指向下面的代码中的.Send命令:

Folks....For some years now I have used the following function in one of my Excel macros to help me compose photo captions from English into French. This AM it started throwing an error, which pointed to the .Send command in the code below:

Public Function getGoogleTranslation(strSource As String, strSourceLang As String, strDestLang As String) As String
Dim strURL As String, x As String

strURL = "http://translate.google.com/translate_a/t?client=t&text=" & _
         Replace(strSource, " ", "%20") & _
         "&hl=en&sl=" & strSourceLang & _
         "&tl=" & strDestLang & "&multires=1&pc=0&rom=1&sc=1"

With CreateObject("msxml2.xmlhttp")
    .Open "get", strURL, False
    .send
    x = .responseText
End With

getGoogleTranslation = Replace(Replace(Split(x, ",")(0), "[", ""), """", "")

End Function

当我将strURL的内容直接复制/粘贴到IE中时,我第一次得到验证码和评论,他们正在检查机器人".第二次直接工作.他们必须设置一个cookie?

When I copy/paste the contents of strURL directly into IE, the first time I got a CAPTCHA and a comment that they are checking for 'robots'. The second time it worked directly. They must be setting a cookie??

这附近还有吗?还是通过简单的短语在宏中翻译的另一种方式?

Is there anyway around this? Or another way to get simple phrases translated in a macro?

谢谢.... RDK

Thanks....RDK

推荐答案

好,使用Google Translate完成!即使像我一样小的VBA使用,它也不再免费.现在通过VBA使用Microsoft Translator.刚刚在Microsoft Azure Marketplace上注册并每月免费获得200万个字符.

OK, done with Google Translate! It is no longer free for VBA usage even as small as mine. Now using Microsoft Translator via VBA. Just signed up on Microsoft Azure Marketplace and get 2 million character/month for free.

我已经使用这个系统好几个月了,它的运行效果与Google Translate一样好.不完美,但是足够好....RDK

I've been using this system for several months now and it works as good as Google Translate did. Not perfect, but good enough....RDK

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

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