2023-10-19
继续努力,又出了几份卷子,例如有理数的乘除基础53份,有理数的乘除及乘方53份,基本七上第一单元就完成了,在出第二单元时,感觉分栏很麻烦,于是决定用表格代替分栏,于是学习了表格的一些操作。
Sub 插入表格(ByVal x As Integer, ByVal y As Integer, ByVal flag As Boolean)
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=x, NumColumns:= _
y, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.Borders.OutsideLineStyle = wdLineStyleNone
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
If flag = True Then
Selection.Tables(1).Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
'不要水平线
End If
Selection.Tables(1).AutoFitBehavior (wdAutoFitFixed)
Selection.Tables(1).Rows.HeightRule = wdRowHeightExactly
Selection.Tables(1).Rows.Height = CentimetersToPoints(0.5)
'Selection.Tables(1).AllowPageBreaks = False
' Selection.Tables(1).AllowAutoFit = False
Selection.MoveDown Unit:=wdLine, Count:=x
End Sub
三个参数,几行几列和是否显示横的边框。这样和分栏的效果差不多。
在上面的出题过程中,会有平方之类的需要上标,上标的操作:
Selection.TypeText text:="x"
Selection.Font.Superscript = wdToggle
Selection.TypeText text:="2"
Selection.Font.Superscript = wdToggle
Selection.TypeText text:=" "
利用这个上标、下标就搞定了。

用表格来代替分栏,效果一样,这样就可以避免分栏的范围选择。