|
楼主 |
发表于 2013-6-24 19:26
|
显示全部楼层
代码以下
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 &(换行)
Next
.Selection.InsertAfter strTemp
.Selection.HomeKey Unit:=wdStory
With .ActiveDocument
With .Sentences(1)
.Font.Bold = True
.Font.Size = 16
.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
.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "\试室安排考生说明" & "\试室安排考生说明.doc", FileFormat:=0
MsgBox .ActiveDocument.FullName
.ActiveDocument.Close False
.Quit
End With
End Sub
Function GetInt(strV As String) As Integer
Dim regex As Object
Dim str As String
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.Pattern = "[^\d]"
GetInt = CInt(.Replace(strV, ""))
End With
End Function
|
|