基于VBA自动成批批改word格式作业

20 篇文章 3 订阅

1方法:利用word VBA编程,选择文件夹中的批量word版本的作业,自动在作业开头加上作业批改信息,方便教师批改大批量作业。

 

图1 程序运行界面,设置等级和评语


图2 选择要批改的作业

 

图3 作业批改成功


图4 作业批改效果图

 

2程序设计

 

(1)界面设计

设计有一个窗体和一个模块


(2)窗体代码

 

(3)模块代码

 

Sub 插入批改文字(oDocAs Document, 评语 As String, 等级 As String)

   

    With oDoc

        .Words(1).Select  '选择文档的第一个词

        .Range.Words(1).InsertBefore(vbCrLf)   '在文档第一个词前插入换行符

    End With

  

    Dim oTable As Table

   

    With oDoc

        Set oTable =.Tables.Add(Range:=.Paragraphs(1).Range, numrows:=1, NumColumns:=1)

                  '加入一个11列的表格

    End With

    With oTable '设置表格格式

        .Borders.InsideLineStyle =wdLineStyleSingle

        For i = 1 To 4

            .Borders(i).LineStyle =Options.DefaultBorderLineStyle

            .Borders(i).LineWidth = wdLineWidth050pt

            .Borders(i).Color = wdColorRed

        Next

    End With

   

    Dim r As Range

    Set r = oTable.Rows(1).Cells(1).Range

   

    With r

        .InsertAfter Text:="已阅"

        .InsertParagraphAfter

        .InsertAfter Text:="成绩:" + 等级

        .InsertParagraphAfter

        .InsertAfter Text:="评语:" + 评语

        .InsertParagraphAfter

        .InsertAfter Text:="批改人:周竹荣"

        .InsertParagraphAfter

        With .Font

            .Size = 16

           

            .Color = wdColorRed

           .Bold = True

        End With

    End With

   oDoc.Range(oTable.Rows(1).Cells(1).Range.Start,oTable.Rows(1).Cells(1).Range.End).Select

    Selection.ParagraphFormat.Alignment =wdAlignParagraphLeft      '左对齐

   

  

   

   

End Sub

 

 

Function 批改作业(评语 As String,等级 As String) As Integer

  Dim myDialog As FileDialog, oFile As Variant,oDoc As Document

  Set myDialog =Application.FileDialog(msoFileDialogFilePicker)

  With myDialog

    .Filters.Clear

    .Filters.Add "所有 WORD 文件","*.doc,*.docx", 1

    .AllowMultiSelect = True

    If .Show <> -1 Then Exit Function

    Dim count As Integer

    count = .SelectedItems.count

    For Each oFile In .SelectedItems

        Set oDoc =Documents.Open(FileName:=oFile, Visible:=False)

        Call 插入批改文字(oDoc, 评语, 等级)

        oDoc.Close True '关闭文档

    Next oFile

  End With

  批改作业 = count

EndFunction

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值