请参: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-5-20 16:11:11
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Option Explicit
Sub RandText()
Dim EnglishChar As Byte, ChineseChar As Integer, MyEnString As String, i As Byte
Dim MyChString As String, MyString As String
Do While i < 10
VBA.Randomize '初始化随机数生成器
'返回一个57~122之间的整数
EnglishChar = VBA.Int(57 * Rnd() + 65)
'如果变量介于91~96之间
If EnglishChar >= 91 And EnglishChar <= 96 Then
Else
'反之
i = i + 1 '累加
'文字累加
MyEnString = MyEnString & Chr(EnglishChar) & ","
End If
Loop
'去掉最后一个,号
MyEnString = Mid(MyEnString, 1, Len(MyEnString) - 1)
i = 0 '初始化变量I值
Do While i < 10
VBA.Randomize '初始化随机数生成器
'返回一个介于-2050~-20319(简体中文汉字)
ChineseChar = -VBA.Int(18269 * Rnd() + 2050)
'如果返回的文字为?号
If Chr(ChineseChar) = "?" Then
Else
' 反之 , 文字累加
MyChString = MyChString & Chr(ChineseChar) & ","
i = i + 1 '累加
End If
Loop
'去掉最后一个,号
MyChString = Mid(MyChString, 1, Len(MyChString) - 1)
'将英文随机文本和中文随机文本赋值于新变量,并加入两个段落标记
MyString = MyEnString & Chr(13) & MyChString & Chr(13)
'光标处插入
Selection.InsertAfter MyString
'光标移到到文档末尾
Selection.EndKey wdStory
End Sub
'---------------------- |