人气 3679

Excel翻译函数完整版-中英韩日通吃 [复制链接]

windy-520 2016-11-28 21:47:32
Excel翻译函数完整版-中英韩日通吃前几天放出一个Excel VBA实现的自动翻译函数,收到很多网友的反馈和点赞,这几天 江苏大侠再继续完善,不光整合了微软的翻译API和有道的翻译API,而且实现了多种语言的翻译,中英韩日多语言通吃。这个功能对于那些做外贸或做国外生意的朋友,或做全球电子商务的人员都非常有用。拿去不谢。
作者:江苏大侠-Office中国

1480340917565222.jpg

1480340917565222.jpg

Excel翻译函数的完整VBA代码:Const Lib = """c:\windows\system32\user32.dll"""Sub Auto_open()  Dim lang  lang = "0:简体中文 1:英文 2:法文 3:德文 4:韩文 5:日文 6:繁体中文 "  Register "fanyi", 3, "单元格,翻译语言", 1, "单元格", _  "文本翻译", """翻译的内容"",""" & lang & """", "CharPrevA"End Sub
Sub Register(FunctionName As String, NbArgs As Integer, _ Args As String, MacroType As Integer, Category As String, _ Descr As String, DescrArgs As String, FLib As String) Application.ExecuteExcel4Macro _ "REGISTER(" & Lib & ",""" & FLib & """,""" & String(NbArgs, "P") _ & """,""" & FunctionName & """,""" & Args & """," & MacroType _ & ",""" & Category & """,,,""" & Descr & """," & DescrArgs & ")"End Sub
Sub Auto_close()  With Application   .ExecuteExcel4Macro "UNREGISTER(""fanyi"")"   .ExecuteExcel4Macro "REGISTER(" & Lib & _    ",""CharPrevA"",""P"",""translator"",,0)"   .ExecuteExcel4Macro "UNREGISTER(""fanyi"")"  End WithEnd Sub
Public Function fanyi(rng, lang)  Dim tlang  tlang = "zh-CHS,en,fr,de,ko,ja,zh-CHT"  URL = "http: //api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=&appId=" _  & "708BEDCB0{{1828123:0}}DC7B6C6A6AB12EF82DFBB611&from=&to=" & Split(tlang, ",")(lang) & "&text=" & rng  Set oH = CreateObject("WinHttp.WinHttpRequest.5.1")  oH.Open "get", URL, False  oH.Send  fanyi = Mid(oH.ResponseText, 3, Len(oH.ResponseText) - 3)End Function
Public Function youdao(zh)  On Error Resume Next  Set JS = CreateObject("msscriptcontrol.scriptcontrol")  JS.Language = "JavaScript"  zh = JS.Eval("encodeURI( '" & Replace(zh, " '", "\ '") & " ');")  sURL = "http: //fanyi.youdao.com/openapi.do?keyfrom=CEFOC2012&key={{819671593:0}}&type=data&doctype=json&version=1.1&q=" & zh  Set oH = CreateObject("WinHttp.WinHttpRequest.5.1")  oH.Open "get", sURL, False  oH.Send  youdao = Split(Split(oH.ResponseText, """]")(0), "[""")(1)End Function
Office中国源创技巧,转载请保留本部落说明学好Excel,可以让你的工作效率成倍提高,让你的薪水也稳步增长,让你的职位也快速提升。
Excel不仅仅是电子表格,它有很多好玩的方式。努力学习吧,每天一个源创技巧,让你信心满满的。
如喜欢此技巧,分享到QQ空间,方便自己以后看
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )|网站地图

GMT+8, 2024-12-22 19:19 , Processed in 0.249317 second(s), 22 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN