|
以下此条代码是根据EXECL数据生成到WORD文档,是否生成的过程中能增加自定义页边距,上3.7,下3.5,左右各2.7 呢?谢谢- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim wordapp As New Word.Application
- Dim mydoc As Word.Document
- Dim myname$, mypath$
- Set d = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
-
- With Worksheets("2017年年度考核汇总")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a3:g" & r)
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 2)) Then
- Set d(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 2)).Exists(arr(i, 3)) Then
- Set d(arr(i, 2))(arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 2))(arr(i, 3)).Exists(arr(i, 7)) Then
- m = 1
- ReDim brr(1 To m)
- Else
- brr = d(arr(i, 2))(arr(i, 3))(arr(i, 7))
- m = UBound(brr) + 1
- ReDim Preserve brr(1 To m)
- End If
- brr(m) = arr(i, 4)
- d(arr(i, 2))(arr(i, 3))(arr(i, 7)) = brr
- Next
- End With
-
- For Each aa In d.keys
- xh = 0
- With wordapp
- Set mydoc = .Documents.Add
- .Visible = True
- With .Selection
- .ParagraphFormat.Alignment = wdAlignParagraphCenter
- .TypeParagraph '隔一行
- .TypeParagraph '隔一行
- .ParagraphFormat.LineSpacingRule = wdLineSpaceExactly '行距固定值33
- .ParagraphFormat.LineSpacing = 45 '行距固定值29
- With .Font
- .Name = "方正小标宋简体"
- .Size = 31.5
- .Bold = wdToggle
- .Color = wdColorRed '字体颜色为红色
- End With
- ' With .ParagraphFormat
- ' .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
- ' .Borders(wdBorderRight).LineStyle = wdLineStyleNone
- ' .Borders(wdBorderTop).LineStyle = wdLineStyleNone
- ' With .Borders(wdBorderBottom)
- ' .LineStyle = wdLineStyleThickThinSmallGap
- ' .LineWidth = wdLineWidth225pt
- ' .Color = wdColorRed
- ' End With
- ' With .Borders
- ' .DistanceFromTop = 1
- ' .DistanceFromLeft = 3.7
- ' .DistanceFromBottom = 1
- ' .DistanceFromRight = 3.7
- ' .Shadow = False
- ' End With
- ' End With
- With Options
- .DefaultBorderLineStyle = wdLineStyleThinThickSmallGap
- .DefaultBorderLineWidth = wdLineWidth225pt
- .DefaultBorderColor = wdColorRed
- End With
- .TypeText Text:="桂南市人力资源和社会保障局"
- .TypeParagraph
- ' .TypeParagraph
- ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' With .ParagraphFormat '生成红色粗横线条
- ' .Borders(wdBorderBottom).LineStyle = wdLineStyleNone '生成粗横线条'先禁用,用WORD生成
- ' End With
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- .TypeParagraph '隔一行
- .ParagraphFormat.LineSpacingRule = wdLineSpaceExactly '行距固定值33
- .ParagraphFormat.LineSpacing = 29 '行距固定值29
- With .Font
- .Name = "方正小标宋简体"
- .Size = 22
- ' .Bold = wdToggle'加粗
- .Color = wdColorAutomatic '旁边体颜色自动
- End With
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- '
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
-
- .TypeText Text:="桂南市政府系统机关、事业单位"
- .TypeParagraph
- .TypeText Text:="科级以下工作人员2017年年度考核结果"
- With .Font
- .Name = "仿宋_GB2312"
- .Size = 14
- End With
- .TypeParagraph
- .TypeParagraph
- .ParagraphFormat.Alignment = wdAlignParagraphLeft
- .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle '单倍行距
- With .Font
- .Name = "仿宋_GB2312"
- .Bold = wdToggle
- End With
- .TypeText Text:=aa & ":"
- .TypeParagraph
- With .ParagraphFormat
- .Alignment = wdAlignParagraphJustify '居中
- .CharacterUnitFirstLineIndent = 2 '空2个字符
- End With
- .TypeText Text:="根据《公务员考核规定(试行)》和中共桂南市委组织部 桂南市人力资源和社会保障局 桂南市绩效考评领导小组办公室《印发<关于开展2017年度全市机关、事业单位科级以下工作人员年度考核工作的实施意见>的通知》的有关规定,经审核,你单位科级以下工作人员2017年年度考核结果为:"
- .TypeParagraph
- With .ParagraphFormat
- .Alignment = wdAlignParagraphJustify '居中
- .CharacterUnitFirstLineIndent = 0 '空2个字符
- ' .FirstLineIndent = CentimetersToPoints(0)
- .CharacterUnitFirstLineIndent = 0
- End With
- With .Font
- .Name = "仿宋_GB2312"
- .Bold = wdToggle
- End With
- With .ParagraphFormat
- .FirstLineIndent = Application.CentimetersToPoints(0)
- .CharacterUnitFirstLineIndent = 0
- End With
-
- For Each bb In d(aa).keys
- xh = xh + 1
- With .Font
- .Name = "黑体" '字体
- .Bold = True
- End With
- If d(aa).Count > 1 Then
- .TypeText Text:=Application.Text(xh, "[Dbnum1]") & "、" & bb
- .TypeParagraph
- End If
- For Each x In Array("优秀", "称职", "基本称职", "不称职", "不定等次", "不参加考核", "待查")
- If d(aa)(bb).Exists(x) Then
- brr = d(aa)(bb)(x)
- With .Font
- .Name = "黑体" '字体
- .Bold = True
- End With
- .TypeText Text:=x & "(" & UBound(brr) & "人):"
- .TypeParagraph
- With .Font
- .Name = "仿宋_GB2312"
- .Bold = False
- End With
- ss = ""
- For i = 1 To UBound(brr)
- ss = ss & Space(2) & brr(i)
- If i Mod 7 = 0 Or i = UBound(brr) Then
- .TypeText Text:=Mid(ss, 3)
- .TypeParagraph
- ss = ""
- End If
- Next
- End If
- Next
- Next
- .TypeParagraph
- .TypeParagraph
- With .Font
- .Name = "仿宋_GB2312"
- .Bold = False
- End With
- .TypeText Text:=Space(40) & "2017年12月12日"
- ' .TypeParagraph'回车键
- End With
- With mydoc
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa
- .Close
- End With
- End With
- ' Exit For '如果连续生成必须禁此行
- Next
- wordapp.Quit
- Set wordapp = Nothing
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码
|
|