|
Option Explicit
Sub test()
Dim ar, iRnd, i&, j&, k&, n&, iNum&, vTemp
ReDim ar(1 To 30, 1 To 4)
ReDim iRnd(1 To 3)
Randomize
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
Do
n = Int(2 * Rnd)
iRnd(2) = Switch(n = 0, "-", n = 1, "+")
For k = 1 To UBound(iRnd) Step 2
iRnd(k) = Int(100 * Rnd)
Next k
If iRnd(2) = "-" Then
If iRnd(1) < iRnd(3) Then vTemp = iRnd(1): iRnd(1) = iRnd(3): iRnd(3) = vTemp
End If
iNum = IIf(iRnd(2) = "-", iRnd(1) - iRnd(3), iRnd(1) + iRnd(3))
Loop Until iNum <= 100
ar(i, j) = Join(iRnd, "") & "="
Next j
Next i
With ActiveDocument
.Range(0).Delete
With .Tables.Add(Range:=Selection.Range, NumRows:=30, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior)
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
.Cell(i, j).Range.Text = ar(i, j)
Next j
Next i
End With
End With
End Sub
|
评分
-
1
查看全部评分
-
|