Sub 漢字轉拼音()
'F2
Const fpath As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ssz3\Google 雲端硬碟\私人\VB\詞典.mdb"
Dim rst As New ADODB.Recordset
Dim cnt As New ADODB.Connection
'Dim p As New ADODB.Parameter
Dim x As String, y As String
Dim cmd As New ADODB.Command
If Selection.Type = wdSelectionNormal Then
x = Selection
Selection.Copy
Else
x = Selection.Previous
End If
cnt.Open fpath
Set cmd.ActiveConnection = cnt
cmd.CommandText = "SELECT 字.字, 拼音.拼音 FROM 拼音 INNER JOIN (字 INNER JOIN 字_注音 ON 字.字ID = 字_注音.字ID) ON 拼音.拼音ID = 字_注音.拼音ID" _
& " WHERE (((字.字)=""" & x & """));"
cmd.CommandType = adCmdText
rst.Open cmd
If rst.EOF Then
Beep
Else
'y = "(" & rst.Fields("拼音").Value & ")"
y = rst.Fields("拼音").Value
With Selection
.Collapse wdCollapseEnd
.TypeText y
.MoveLeft wdCharacter, Len(y), wdExtend
.Font.NameAscii = "NSimSun"
.Font.ColorIndex = wdRed
.Font.Size = 16
.Range.HighlightColorIndex = wdYellow
.Collapse wdCollapseEnd
End With
Selection.Document.Save
End If
rst.Close
cnt.Close
End Sub