打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
[原创]
Public Sub TranslateAll()
'++++++++++++++++++++++++++++++++++++++++++++++++
'+++   Code By   icy/忽又一天                   +++
'+++   Email: wzw.icy@gmail.com                 +++
'+++   Q   Q: 365052003                         +++
'+++   Blog: Http://hi.baidu.com/suddenday/   +++
'++++++++++++++++++++++++++++++++++++++++++++++++
    On Error Resume Next
    Dim i As Integer, j As Integer
    For i = 0 To 200
        For j = 0 To 20
             ReplaceCellTxt i, j
        Next
    Next
    
End Sub

Private Sub ReplaceCellTxt(ByVal RowIndex As Double, ByVal ColIndex As Double)

    '替换指定单元格中的中文字符
    On Error Resume Next
    Dim i As Integer
    Dim PreText As String, CnText As Variant
     PreText = Cells(RowIndex, ColIndex)
     Debug.Print PreText
    
    If GetChn(PreText) <> "" Then
         CnText = Split(GetChn(PreText), ",")
    End If
    
    For i = 0 To UBound(CnText)
    
     CurText = TranslateWord(CnText(i))
     Debug.Print CurText
    
    If (Not CurText = "NotFound") And (Not Trim(CurText) = "") Then
         PreText = Replace(PreText, CnText(i), CurText)
         Cells(RowIndex, ColIndex) = PreText
    End If
    
    Next
    
End Sub

Private Function TranslateWord(ByVal StrWord As String) '查找指定字符串在词典中的解释

    On Error Resume Next
    Dim StrTemp As String
    Dim StrWords As Variant
    Open "D:\Dic.txt" For Input As #1
     TranslateWord = "NotFound"
    
    Do While Not EOF(1)
    
        Line Input #1, StrTemp
         Debug.Print StrTemp
         StrWords = Split(StrTemp, vbTab)
        If Trim(StrWords(0)) = Trim(StrWord) And UBound(StrWords) > 0 Then
             TranslateWord = StrWords(1)
            Exit Do
        End If
    
    Loop
    
    Close #1
    
End Function

Private Function GetChn(ByVal Str As String) As String  '截取字符串中的中文

    Dim i As Integer, j As Integer
    Dim ChnStr As String
    Dim IsPreCn As Boolean
     IsPreCn = False

    For i = 1 To Len(Str)
    
        If Asc(Mid(Str, i, 1)) < 0 Then
            If IsPreCn Then
                 ChnStr = ChnStr & Mid(Str, i, 1)
            Else
                 ChnStr = ChnStr & "," & Mid(Str, i, 1)
            End If
             IsPreCn = True
        Else
             IsPreCn = fasle
        End If
    Next
    
    If Mid(ChnStr, 1, 1) = "," Then
         ChnStr = Mid(ChnStr, 2, Len(ChnStr))
    End If
    
     GetChn = ChnStr

     Debug.Print GetChn

End Function

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
0180 轻松记 text context pretext
使用cntext训练Glove词嵌入模型
使用css控制GridView控件的样式
VA14.3 小结
Dim?35204?Flowers?Of?Paris
趣味英语起源论第306期:Text 课文
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服