|
楼主 |
发表于 2020-1-12 10:29
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Public Function fanyi(Rng As String)
- Dim xml
- Dim URL$, EngSentence$
- Set xml = CreateObject("MSXML2.XMLHTTP")
- aasc = Asc(Rng)
- If aasc > 64 And aasc < 123 Then
- URL = "enN&tl=zh-CN&ie=UTF-8&prev=_m&q=" & Rng
- Else
- URL = "zh-CN&tl=enN&ie=UTF-8&prev=_m&q=" & GetURL(Rng)
- End If
- URL = "https://translate.google.cn/m?hl=en&sl=" & URL
- With xml
- .Open "GET", URL, False
- .send
- V = .responseText
- If InStr(V, "t0"">") > 0 Then
- fanyi = Split(Split(V, "t0"">")(1), "<")(0)
- End If
- End With
- End Function
- Function ChrU(txt)
- txt = "\u6666" & txt
- Sr = Split(txt, "\u") '按汉字单位拆分
- For i = 0 To UBound(Sr) '遍历
- If Len(Sr(i)) > 3 Then Sr(i) = ChrW("&H" & Left(Sr(i), 4)) & Mid(Sr(i), 5)
- '如果4个字符以上 则取前4个字符(汉字的16进制国际双位码值) 添加"&H"转为16进制数
- '然后用ChrW函数即可返回汉字
- Next
- ChrU = Mid(Join(Sr, ""), 2) '把转换后的汉字以及其余字符合并起来返回
- End Function
- Function sjc$() '时间戳
- 'sjc = (Now - 25569 - 1 / 3) * 86400
- sjc = (Now - 25570 + 2 / 3) * 86400 + 100
- sjc = "=" & Left(sjc & Rnd * 100000, 13)
- 'Debug.Print sjc
- 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
- '如果一律转码是: GetURL = GetURL & "%" & Right("0" & Hex(a(i)), 2)
复制代码 |
|