我也试着做了一个: '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2007-2-23 9:55:03 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0166^The Code CopyIn [用户窗体-UserForm1]^' '* ----------------------------- Private Sub CommandButton1_Click() Dim myRand As Integer, myString As String, myArray() As Integer Dim Num1 As Integer, Num2 As Integer, rndCount As Integer Num1 = Me.TextBox1.Value Num2 = Me.TextBox2.Value If Num2 > Num1 Then MsgBox "随机个数不能大于随机数的取值范围!" Exit Sub End If ListBox1.Clear ReDim myArray(Num2 - 1) While rndCount < Num2 myRand = Int(Rnd * Num1 + 1) If VBA.InStr(myString, "[" & myRand & "]") = 0 Then myString = myString & "[" & myRand & "]" myArray(rndCount) = myRand rndCount = rndCount + 1 End If Wend Me.ListBox1.List() = myArray If Me.CheckBox1.Value = True Then ActiveDocument.Content.InsertAfter VBA.Join(myArray, Chr(13)) End Sub '----------------------
[此贴子已经被作者于2007-2-23 9:55:27编辑过] |