|
- Sub 证书表格合并()
- '更新/2018-11-28/TEST-OK/彻底定稿
- If ActiveDocument.Saved = False Then MsgBox "未保存!", 0 + 16: End
- Dim doc As Document, d$, a, b, n&, m&, q$, t As Table, c As Cell, r As Row, i&, s$, u$
- Set doc = ActiveDocument
- d = MsgBox("<是>:默认字段 <否>:表格一字段 <取消>:自定义", 3 + 48)
- If d = vbYes Then
- n = 1
- m = 5
- a = Array("证书编号", "课题", "姓名", "单位", "等级")
- ElseIf d = vbNo Then
- n = 2
- Else
- n = 3
- q = InputBox("", "请输入自定义字段(空格分隔)!", "姓名 单位 课题 等级 证书编号")
- If q = "" Then End
- b = Split(q, " ")
- m = UBound(b) + 1
- End If
- 证书表格预置
- If n = 2 Then m = doc.Tables(1).Columns.Count
- With doc
- For Each t In .Tables
- With t
- '调整字段
- For i = 1 To m
- If n = 1 Then
- s = a(i - 1)
- ElseIf n = 2 Then
- s = doc.Tables(1).Rows(1).Cells(i).Range.Text
- s = Left(s, Len(s) - 2)
- ElseIf n = 3 Then
- s = b(i - 1)
- End If
- If .Rows(1).Range Like "*" & s & "*" Then
- .Rows(1).Select
- With Selection
- .Find.Execute s
- If .Information(17) <> i Then
- .Columns(1).Select
- .Cut
- t.Columns(i).Select
- .Paste
- End If
- End With
- Else
- If i = 1 Then .Cell(1, 1).Select
- With Selection
- If i = 1 Then .InsertColumns Else .InsertColumnsRight
- .Cells(1).Range.Text = s
- End With
- End If
- Next i
- '删除末列
- If n = 1 Then
- u = "等级"
- ElseIf n = 2 Then
- u = doc.Tables(1).Rows(1).Cells(doc.Tables(1).Columns.Count).Range.Text
- u = Left(u, Len(u) - 2)
- ElseIf n = 3 Then
- u = b(UBound(b))
- End If
- Do While Not .Rows(1).Cells(.Columns.Count).Range Like u & "*"
- .Columns(.Columns.Count).Delete
- Loop
- End With
- Next
- '合并数据
- Do While .Tables.Count > 1
- With .Tables(2)
- .Rows(1).Delete
- .Select
- End With
- With Selection
- .MoveEnd 1, -1
- .Cut
- End With
- .Tables(1).Range.Characters.Last.Select
- With Selection
- .MoveRight 12, 1
- .Paste
- End With
- .Characters(1).Copy
- Loop
- End With
- 证书表格后期
- End Sub
- Sub 证书表格预置()
- '更新/2018-11-28/TEST-OK/彻底定稿
- Dim t As Table, c As Cell, r As Row, x&, y&, z&, j&, k&, e&
- With ActiveDocument
- With .Content.Find
- .Execute "^13", , , , , , , , , "", 2
- .Execute "^11", , , , , , , , , "", 2
- End With
- For Each t In .Tables
- With t
- '取消环绕
- With .Rows
- .WrapAroundText = False
- .Alignment = wdAlignRowLeft
- .LeftIndent = CentimetersToPoints(0)
- End With
- '是否规则(e=1=规则/e=0=不规则)
- With .Range
- x = .Information(wdEndOfRangeRowNumber)
- y = .Information(wdEndOfRangeColumnNumber)
- z = .Cells.Count
- End With
- If x <> 1 Then
- If z = x * y Then
- For k = 1 To y
- For j = 1 To x - 1
- If .Cell(j + 1, k).Width = .Cell(j, k).Width Then e = 1 Else e = 0
- If e = 0 Then Exit For
- Next j
- If e = 0 Then Exit For
- Next k
- Else
- e = 0
- End If
- Else
- e = 1
- End If
- If e = 0 Then .Select: MsgBox "表格不规则!", 0 + 16: End
- End With
- Next
- For Each t In .Tables
- With t
- '删除空格
- .Select
- Selection.MoveEnd
- CommandBars.FindControl(ID:=122).Execute
- '删除表头空格
- With .Rows(1).Range.Find
- .Execute "^w", , , , , , , , , "", 2
- .Execute " ", , , , , , , , , "", 2
- End With
- '规范字段
- For Each c In .Rows(1).Cells
- With c.Range
- If .Text Like "*序号*" Then
- .Text = "序号"
- ElseIf .Text Like "*姓名*" Then
- .Text = "姓名"
- ElseIf .Text Like "*课题*" Then
- .Text = "课题"
- ElseIf .Text Like "*[单学][位校]*" Then
- .Text = "单位"
- ElseIf .Text Like "*[等奖][级项]*" Then
- .Text = "等级"
- ElseIf .Text Like "*编号*" Then
- .Text = "证书编号"
- End If
- If Len(.Text) = 2 Then .Text = "空列"
- End With
- Next
- '删除空列
- Do While .Rows(1).Range Like "*空列*"
- .Rows(1).Select
- With Selection
- .Find.Execute "空列"
- .Columns.Delete
- End With
- Loop
- '删除序号
- .Rows(1).Select
- With Selection.Find
- .Execute "序号"
- If .Found = True Then .Parent.Columns.Delete
- End With
- '删除空行
- For Each r In .Rows
- If Len(Replace(Replace(r.Range, vbCr, ""), Chr(7), "")) = 0 Then r.Delete
- Next
- '蓝色粉红
- .Range.Font.Color = wdColorBlue
- .Rows(2).Range.Font.Color = wdColorPink
- End With
- Next
- End With
- End Sub
- Sub 证书表格后期()
- '更新/2018-11-28/TEST-OK/彻底定稿
- With ActiveDocument
- If Not .Paragraphs(1).Range.Information(12) Then .Paragraphs(1).Range.Delete
- .Range(Start:=.Tables(1).Range.End, End:=.Content.End).Delete
- With .Tables(1).Rows(1).Range.Font
- .Color = wdColorRed
- .Bold = True
- End With
- With .Tables(1)
- With .Range
- .Font.Size = 10.5
- .ParagraphFormat.Space1
- End With
- With .Rows
- .HeightRule = wdRowHeightAtLeast
- .Height = CentimetersToPoints(0)
- End With
- .Select
- .AutoFitBehavior (wdAutoFitContent)
- .Select
- .AutoFitBehavior (wdAutoFitWindow)
- End With
- ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
- Selection.HomeKey 6
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|