请参:
代码已经设置完毕,你只需确认数据源即可,我此处修改了一下,为“成绩表1”,
注意事项:一:必须启用宏,工具/宏/安全级:低。
二:如果数据源出现问题,可关闭该主文档后再次打开(重新初始化类模块)
ujXRkovo.zip
(23.86 KB, 下载次数: 119)
以下代码供参考:
'* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-1-22 10:34:16
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [类模块-EventClassModule]^'
'* -----------------------------
Public WithEvents App As Word.Application '在类模块中声明对应于事件的对象变量。
'编写指定事件的过程。
Private Sub App_MailMergeBeforeRecordMerge(ByVal Doc As Document, Cancel As Boolean)
Dim i As Byte
'如果主文档数据源中的字段1中的数据小于60(分)时
For i = 5 To 25
If Doc.MailMerge.DataSource.DataFields(i).Value < 60 Then
'主文档表格的第二行第二列(相当于B2)中的字体为红色
Select Case i
Case 5 To 9
Doc.Tables(2).Cell(2, i - 3).Range.Font.Color = wdColorRed
Case 10 To 11
Doc.Tables(2).Cell(2, i - 1).Range.Font.Color = wdColorRed
Case 12 To 16
Doc.Tables(2).Cell(3, i - 10).Range.Font.Color = wdColorRed
Case 17 To 18
Doc.Tables(2).Cell(3, i - 8).Range.Font.Color = wdColorRed
Case 19 To 23
Doc.Tables(2).Cell(4, i - 17).Range.Font.Color = wdColorRed
Case 24 To 25
Doc.Tables(2).Cell(4, i - 15).Range.Font.Color = wdColorRed
End Select
Else '否则恢复默认字体颜色
Select Case i
Case 5 To 9
Doc.Tables(2).Cell(2, i - 3).Range.Font.Color = wdColorAutomatic
Case 10 To 11
Doc.Tables(2).Cell(2, i - 1).Range.Font.Color = wdColorAutomatic
Case 12 To 16
Doc.Tables(2).Cell(3, i - 10).Range.Font.Color = wdColorAutomatic
Case 17 To 18
Doc.Tables(2).Cell(3, i - 8).Range.Font.Color = wdColorAutomatic
Case 19 To 23
Doc.Tables(2).Cell(4, i - 17).Range.Font.Color = wdColorAutomatic
Case 24 To 25
Doc.Tables(2).Cell(4, i - 15).Range.Font.Color = wdColorAutomatic
End Select
End If
Next
End Sub
'----------------------
'* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-1-22 10:34:36
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------
Dim X As New EventClassModule '从其他模块中初始化已声明的对象。
Private Sub Document_Open()
Set X.App = Word.Application
End Sub
'----------------------
|