ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 23685|回复: 65

[分享] 分享EXCEL批量英译中谷歌翻译,无需安装插件即可实现

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2019-11-19 13:27 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

不喜欢有道翻译或者百度翻译的小伙伴可以看一下
能下拉批量翻译,需要联网,稍微更改代码能实英文翻译为其它语言。
中译英暂时还没调试好,能实现中译英的小伙伴可以告诉我!
效果如图

image.png

Public Function EnToCh(rng As String)
    Dim xml
    Dim url$, EngSentence$
    Set xml = CreateObject("MSXML2.XMLHTTP")
   'EngSentence = URLEncodePlus(rng.Text)
   'url = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & EngSentence
    url = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & rng
    With xml
      .Open "GET", url, False
      .send
       If InStr(.responseText, "<div dir=""ltr"" class=""t0"">") > 0 Then
            EnToCh = Split(Split(.responseText, "<div dir=""ltr"" class=""t0"">")(1), "</div><")(0)
        End If
    End With
End Function

评分

2

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-11-19 15:13 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
楼主上传附件看看

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-19 16:43 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
程然2234 发表于 2019-11-19 15:13
楼主上传附件看看

你直接复制代码就好了

TA的精华主题

TA的得分主题

发表于 2019-11-20 17:29 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2019-11-20 18:33 | 显示全部楼层
跟学习下。谢谢老师!
Public Function EnToCh(rng As String, z)
    Dim xml
    Dim URL$, EngSentence$
    Set xml = CreateObject("MSXML2.XMLHTTP")
   'EngSentence = URLEncodePlus(rng.Text)
   'url = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & EngSentence
    If z = 1 Then
        URL = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & rng
    Else
        URL = "https://translate.google.cn/m?hl=en&sl=zh-CN&tl=enN&ie=UTF-8&prev=_m&q=" & GetURL(rng)
    End If
    With xml
      .Open "GET", URL, False
      .send
       If InStr(.responseText, "<div dir=""ltr"" class=""t0"">") > 0 Then
            EnToCh = Split(Split(.responseText, "<div dir=""ltr"" class=""t0"">")(1), "</div><")(0)
        End If
    End With
End Function

Function GetURL$(txt$)
'Dim a() As Byte
'a = StrConv(txt, vbFromUnicode, &H804)
    For i = 1 To Len(txt)
        txt1 = Mid(txt, i, 1)
        If Abs(Asc(txt1)) < 128 Then
            GetURL = GetURL & txt1
        Else
            GetURL1 = Application.Hex2Bin(left(Hex(AscW(txt1)), 2), 8)
            GetURL1 = GetURL1 & Application.Hex2Bin(right(Hex(AscW(txt1)), 2), 8)
            GetURL1 = Application.Replace(Application.Replace(GetURL1, 11, , 10), 5, , 10)
            GetURL2 = "%E" & Application.Bin2Hex(left(GetURL1, 4))
            GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 5, 8))
            GetURL2 = GetURL2 & "%" & Application.Bin2Hex(Mid$(GetURL1, 13, 8))
            GetURL = GetURL & GetURL2
        End If
    Next
End Function

评分

2

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-11-20 20:38 | 显示全部楼层
请参考
中英文互译.rar (15.1 KB, 下载次数: 1230)

评分

3

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-11-20 20:40 | 显示全部楼层
优化下
Public Function EnToCh(rng As String)
    Dim xml
    Dim URL$, EngSentence$
    Set xml = CreateObject("MSXML2.XMLHTTP")
   'EngSentence = URLEncodePlus(rng.Text)
   'url = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & EngSentence
    Debug.Print Asc(rng)
    aasc = Asc(rng)
    If aasc > 64 And aasc < 123 Then
        URL = "https://translate.google.cn/m?hl=en&sl=enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & rng
    Else
        URL = "https://translate.google.cn/m?hl=en&sl=zh-CN&tl=enN&ie=UTF-8&prev=_m&q=" & GetURL(rng)
    End If
    With xml
      .Open "GET", URL, False
      .send
       If InStr(.responseText, "<div dir=""ltr"" class=""t0"">") > 0 Then
            EnToCh = Split(Split(.responseText, "<div dir=""ltr"" class=""t0"">")(1), "</div><")(0)
        End If
    End With
End Function

评分

1

查看全部评分

TA的精华主题

TA的得分主题

发表于 2019-11-20 20:42 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-20 23:05 | 显示全部楼层
YZC51 发表于 2019-11-20 20:42
6楼附件, 中英文互译啦

牛逼牛逼。。我终于知道原因了

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-20 23:18 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-28 16:34 , Processed in 0.042203 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表