有关Word创建英语练字模板的宏

来源:互联网 发布:淘宝上买精密管犯法吗? 编辑:程序博客网 时间:2024/04/28 19:00

宏代码如下

==============================================================

Sub Add4line()
   '注意录入的字体必须设置为"Times New Roman",字号为13.5号,并且每一行为一个段落
    Dim i As Paragraph, MyLine As Shape, Myshape As Shape, myRange As Range, H As Integer
    Dim WP As Single, PP As Single, TP As Single, lp As Single, RP As Single, n As Byte
    On Error Resume Next '忽略错误
    With ActiveDocument.PageSetup
        WP = .PageWidth '页面宽度
        lp = .LeftMargin '左页边距
        RP = .RightMargin '右页边距
    End With
    '根据区域不同,进行设置,如果未选定内容则在全文档中进行,反之则在选定区域中进行
    If Selection.Type = wdSelectionIP Then
        Set myRange = ActiveDocument.Content
    Else
        Set myRange = Selection.Range
    End If
    Application.ScreenUpdating = False '关闭屏幕更新
    For Each i In myRange.Paragraphs '在指定区域中循环
    H = H + 1 '计数
        With i.Range '对段落进行初始化设置,以达到要求
            .Font.Size = 17 '字号
            .Font.Name = "Rai" '字体
            .Font.Color = wdColorBlueGray
            .ParagraphFormat.SpaceBefore = 0 '段前为0
            .ParagraphFormat.SpaceAfter = 0 '段后为0
            .ParagraphFormat.LineSpacing = 23 '行距为23磅
            TP = i.Range.Information(wdVerticalPositionRelativeToPage) + 5 '取得段落的垂直位置
            For n = 0 To 3 '循环划直线
                Set MyLine = ActiveDocument.Shapes.AddLine(lp, TP + 8 * n, WP - RP, TP + 8 * n)
                MyLine.Name = "Line" & H & n
                MyLine.Line.ForeColor.RGB = RGB(Red:=150, Green:=150, Blue:=150)
                If n = 0 Then MyLine.Line.ForeColor.RGB = RGB(Red:=0, Green:=0, Blue:=150)
                If n = 2 Then MyLine.Line.Weight = 1.5 '当N为2时的直线为1.5磅
                If n = 3 Then MyLine.Line.ForeColor.RGB = RGB(Red:=150, Green:=0, Blue:=0)
            Next
            '组合四条直线
           Set Myshape = ActiveDocument.Shapes.Range(Array _
            ("Line" & H & 0, "Line" & H & 1, "Line" & H & 2, "Line" & H & 3)).Group
            Myshape.ZOrder msoSendBehindText '浮于文字下方
           
        End With
    Next
    Application.ScreenUpdating = True '恢复屏幕更新
End Sub

原创粉丝点击