|
发表于 2013-6-25 10:39
|
显示全部楼层
本楼为最佳答案
- Private Sub CommandButton1_Click()
- Dim objWord As Object
- Set objWord = CreateObject("word.application")
- Dim intSum As Integer
- Dim strT() As String
- Dim arr, i As Long, K As Long
- Dim strTemp As String
- strTemp = "试室安排考生说明" & vbCr
- arr = Range("a1").CurrentRegion
- With objWord
- .Documents.Add
- For i = LBound(arr) + 1 To UBound(arr)
- intSum = 0
- strT = Split(CStr(arr(i, 2)), "、")
- For K = LBound(strT) To UBound(strT)
- intSum = intSum + GetInt(strT(K))
- Next
- 'strTemp = strTemp & " 第" & Replace(Application.WorksheetFunction.Text(arr(i, 1), "[DBNum1][$-804]General"), "一十", "十") & "试室" & "(共" & intSum & "人):" & vbCrLf & " " & arr(i, 2) & "。" & vbCrLf '& "。" (每句结束加句号),vbcrlf &(换行)
- strTemp = strTemp & "第" & Replace(Application.WorksheetFunction.Text(arr(i, 1), "[DBNum1][$-804]General"), "一十", "十") & "试室" & "(共" & intSum & "人):" & vbCrLf & arr(i, 2) & "。" & vbCrLf '& "。" (每句结束加句号),vbcrlf &(换行)
- Next
- .Selection.InsertAfter strTemp
- .Selection.HomeKey Unit:=wdStory
- With .ActiveDocument
- With .Sentences(1)
- .Font.Bold = True
- .Font.Size = 24
- .Font.Name = "黑体"
- .ParagraphFormat.Alignment = wdAlignParagraphCenter '居中
- .ParagraphFormat.LineSpacing = 20
- End With
- End With
- With .Selection.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Replacement.Font.Bold = True
- .Text = "第 [0-9]{1,} 教室"
- .Replacement.Text = ""
- .Forward = True
- .Wrap = wdFindContinue
- .Format = True
- .MatchWildcards = True
- .Execute Replace:=wdReplaceAll
- End With
- With .ActiveDocument
- For i = 2 To .Sentences.Count Step 2
- With .Sentences(i)
- .Font.Bold = True '加粗
- .Font.Size = 16 '字号
- .Font.Name = "仿宋_GB2312" '字体
- End With
- With .Sentences(i + 1)
- .Font.Size = 16 '字号
- .Font.Name = "仿宋_GB2312" '字体
- End With
- Next
-
- With .Range(Start:=.Paragraphs(2).Range.Start, _
- End:=.Paragraphs(.Paragraphs.Count).Range.End)
- With .ParagraphFormat
- .FirstLineIndent = CentimetersToPoints(0)
- .CharacterUnitFirstLineIndent = 2
- End With
- End With
- .SaveAs Filename:=ThisWorkbook.Path & "\试室安排考生说明" & "\试室安排考生说明.doc", FileFormat:=0
- MsgBox .FullName
- .Close False
- End With
- .Quit
- End With
- End Sub
复制代码 |
评分
-
查看全部评分
|