|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我谷歌翻译用的这个:
- Function CN2EN(rng)
- Dim xml
- Dim url$, EngSentence$
- Set xml = CreateObject("MSXML2.XMLHTTP")
- EngSentence = Escape(rng.Value)
- url = "https://translate.google.cn/m?hl=zh-CN&sl=zh-CN&tl=en&ie=UTF-8&prev=_m&q=" & EngSentence
- With xml
- .Open "GET", url, False
- .Send
- If InStr(.ResponseText, "<div dir=""ltr"" class=""t0"">") > 0 Then
- CN2EN = Split(Split(.ResponseText, "<div dir=""ltr"" class=""t0"">")(1), "</div><")(0)
- End If
- End With
- End Function
- Function URLEncodePlus(strURL)
- 'ANSI编码,空格处理成+号
- Dim i
- Dim tempStr
- For i = 1 To Len(strURL)
- If Asc(Mid(strURL, i, 1)) < 0 Then
- tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, i, 1)))), 2)
- tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, i, 1)))), Len(CStr(Hex(Asc(Mid(strURL, i, 1))))) - 2) & tempStr
- URLEncodePlus = URLEncodePlus & tempStr
- ElseIf (Asc(Mid(strURL, i, 1)) >= 65 And Asc(Mid(strURL, i, 1)) <= 90) Or _
- (Asc(Mid(strURL, i, 1)) >= 97 And Asc(Mid(strURL, i, 1)) <= 122) Or _
- (Asc(Mid(strURL, i, 1)) >= 48 And Asc(Mid(strURL, i, 1)) <= 57) Then
- URLEncodePlus = URLEncodePlus & Mid(strURL, i, 1)
- Else
- tempStr = Mid(strURL, i, 1)
- Select Case tempStr
- Case ".", "-", "~", "_" '如果发现网站有其他不需要编码的字符,放在这里
- URLEncodePlus = URLEncodePlus & tempStr
- Case " "
- URLEncodePlus = URLEncodePlus & "+"
- Case Else
- URLEncodePlus = URLEncodePlus & "%" & Hex(Asc(tempStr))
- End Select
- End If
- Next
- End Function
- Function GetURL$(txt$)
- Dim a() As Byte: a = StrConv(txt, vbFromUnicode, &H804)
- For i = 0 To UBound(a)
- GetURL = GetURL & IIf(a(i) < 128, Chr(a(i)), "%" & Hex(a(i)))
- Next
- End Function
- Function Escape(ByVal strText As String) As String
- Set JS = CreateObjectx86("msscriptcontrol.scriptcontrol")
- JS.Language = "JavaScript"
- Escape = JS.Eval("encodeURIComponent('" & Replace(Replace(strText, "'", "\'"), Chr(10), "") & "');")
- End Function
复制代码 |
评分
-
1
查看全部评分
-
|