|
在模块中加入:
Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrcommand As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private mciID As Integer
Public Declare Function DeleteUrlCacheEntry Lib "wininet" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Function GoogleSayCN(ByVal sWord As String)
On Error Resume Next
Dim objJs As Object
Dim sFile As String
Dim sTmpPath As String
sTmpPath = Space(255)
GetTempPath 255, sTmpPath
sTmpPath = Left(sTmpPath, InStr(sTmpPath, Chr(0)) - 1)
sFile = sTmpPath & mciID Mod 2 & ".mp3"
mciID = mciID + 1
Set objJs = CreateObject("MSScriptControl.ScriptControl")
objJs.Language = "JavaScript"
sWord = objJs.Eval("encodeURI('" & Replace(sWord, "'", "\'") & "');")
URLDownloadToFile 0, "http://translate.google.cn/translate_tts?ie=UTF-8&q=" & sWord & "&tl=zh-CN&prev=input" & Rnd(), sFile, 0, 0 '中文'
DeleteUrlCacheEntry "http://translate.google.cn/translate_tts?ie=UTF-8&q=" & sWord & "&tl=zh-CN&prev=input" '清除缓存
mciExecute "play " & sFile
End Function
在sheet1代码中:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Row > 10 And Target <> "" Then
Set c = Sheets("cy").Range("a:a").Find(Target, LookIn:=xlValues, lookat:=1)
If Not c Is Nothing Then
Range("d9") = c.Offset(0, 1)
Range("e10") = c.Value
For j = 1 To 2
GoogleSayCN Target.Offset(0, 0)
DoEvents
Application.Wait (Now + TimeValue("0:00:02"))
Next
End If
End If
End Sub
联网前提下,可语音朗读了——不过Google的中文发音可不算标准哟.......
|
|