以下是引用守柔在2006-4-4 12:00:04的发言:TO KONGGS 你的修改很好。 我们再来优化一下,把二次循环变为一次循环,你看如何? Sub 不重复字符知多少() Dim AllText As String, B As String Dim i As Long, StartTime As Single Dim OnlyText As String StartTime = Timer AllText = ActiveDocument.Content.Text For i = 1 To Len(AllText) B = Mid(AllText, i, 1) If B Like "[一-龥]" Then '如果属于汉字字符(CJK统一汉字字符集) If OnlyText = "" Then OnlyText = B '为变量赋初值 ElseIf VBA.InStr(OnlyText, B) = 0 Then '如果在OnlyText变量中,没有出现过的字符,则加入该变量字符集中 OnlyText = OnlyText & B End If End If Next MsgBox Len(OnlyText), vbOKOnly, Timer - StartTime End Sub 我也想知道楼主的方法,可是版主,我不懂VB,不明白这样的代码,在Word中如何用?简直是看天书。 [em04] |