如何检查一个string(或单元格)中是否有kajji字符?

我为一家日本公司工作。 因为发给我的excel表格大部分都是日文。 所以我创build了一个Excelmacros,提示用户select他们想要翻译的单元格范围。 macros循环通过单元格值范围,将其复制到Google翻译文本框中,等待翻译,复制翻译并将单元格值设置为翻译。

现在所有这些都在工作,我可以翻译任何我投掷的范围。 我遇到的问题是翻译文档所花费的时间。 我尽我所能,加快了与谷歌的连接。 接下来我看到放慢macros观的一个事实是,我无法find一个简单的方法来确定一个单元格是否包含任何日语(平假名,片假名,汉字)。 所以我正在寻找一个基本上这样的function:

Function isJapanese(cell as Range) If cell.Value is Japanese Then isJapanese = True Else isJapanese = False End If End Function 

我已经在检查string是否包含拉丁字母(这使得它跳过一些单元格),某些符号,以及任何其他字符或string,我认为这是唯一的英文单元格。

下面是我到目前为止的代码(我正在使用用户表单来获取翻译function的variables)

 Function Translate_Range(rng As String, in_exp As String, out_exp As String) As Boolean Dim japCheck As Boolean, japCount As Integer, cellAddress As String, transText As String, langDesired As String, wkb As String, sht As String, searchRange As Range, doneCheck As Boolean doneCheck = False wkb = ActiveWorkbook.Name sht = ActiveSheet.Name Workbooks(wkb).Worksheets(sht).Activate japCount = 0 japCheck = True Set searchRange = Range(rng) For Each cell In searchRange If cell.Value <> "" And InStr(cell.Text, "mm") = 0 And InStr(cell.Text, "±") = 0 Then japCheck = IsAlpha(cell.Text) If japCheck = True Then GoTo NextIteration Else transText = translate_string(cell.Address, in_exp, out_exp) ActiveSheet.Range(cell.Address).Value = transText End If End If NextIteration: Next doneCheck = True Translate_Range = doneCheck End Function Private Function translate_string(cell As String, input_exp As String, output_exp As String) Dim str As String str = ActiveSheet.Range(cell).Value Set IE = CreateObject("InternetExplorer.Application") IE.Visible = False IE.navigate "http://translate.google.com/#" & input_exp & "/" & output_exp & "/" & str Do Until IE.readyState = 4 DoEvents Loop Do Until result_data <> "" CLEAN_DATA = Split(Application.WorksheetFunction.Substitute(IE.Document.getElementById("result_box").innerHTML, "</SPAN>", ""), "<") For i = LBound(CLEAN_DATA) To UBound(CLEAN_DATA) result_data = result_data & Right(CLEAN_DATA(i), Len(CLEAN_DATA(i)) - InStr(CLEAN_DATA(i), ">")) Next Loop IE.Quit translate_string = result_data End Function Private Function IsAlpha(strValue As String) As Boolean IsAlpha = strValue Like WorksheetFunction.Rept("[a-zA-Z]", Len(strValue)) End Function 

我觉得必须有一个用于汉字字符的Unicode协议。 对于这样的事情,我只是一个没有经验的人(我是一个机械工程师,为了让我的生活更轻松,所以我对这个技术编程主题的知识缺乏抱歉)

这个从我所链接的答案中大量借用的子句可以确定一个string是否有任何拉丁字符:

 Sub t() Dim k As Long Dim myString As String myString = Range("Z1").Value 'Edit this as needed Dim latinChars As Long latinChars = 0 For k = 1 To Len(myString) If IsLatin(Mid(myString, k, 1)) Then ' Has latin characters latinChars = latinChars + 1 End If Next k If latinChars = 0 Then ' Doesn't have latin characters Debug.Print "Doesn't have latin characters" Else ' Has latin characters Debug.Print "Has latin characters" End If End Sub Function IsLatin(Str As String) As Boolean IsLatin = True For i = 1 To Len(Str) IsLatin = IsLatin And Abs(AscW(Mid(Str, i, 1)) - 64) < 64 Next i End Function