|
也可试试如下代码,基本思路是seq域和查找替换:
Sub test()
Dim a As Integer, b As Integer
Dim myRange As Range, c As Integer, w As Single
a = Val(InputBox("一行要输入几小题?", , 10))
b = Val(InputBox("要输入几行?", , 5))
Application.ScreenUpdating = False
Selection.Text = String(a * b, vbTab)
Set myRange = Selection.Range
With myRange
.Fields.Add ActiveDocument.Range(.Start, .Start), wdFieldSequence, "a", False
.Fields(1).Cut
With .Find
.MatchWildcards = True
.Execute vbTab & "{" & a & "}", replacewith:="^&^p", Replace:=wdReplaceAll
.Execute vbTab, replacewith:="^c.^&", Replace:=wdReplaceAll
.Replacement.Font.Underline = wdUnderlineSingle
.Execute vbTab, replacewith:="^32^&", Replace:=wdReplaceAll
End With
w = myRange.PageSetup.TextColumns.Width / a
For c = 1 To a
.ParagraphFormat.TabStops.Add c * w
Next
.Fields.Update
'.Fields.Unlink '取消域链接
'If .Start <> .Paragraphs.First.Range.Start Then .InsertBefore vbCrLf
End With
Application.ScreenUpdating = True
End Sub |
|