点击文件名下载附件
图1:
图2:
代码如下:(下段代码hwc2ycy老师编写,在此先谢谢hwc2ycy老师了)
Private Sub CommandButton1_Click()
Dim objWord As Object
Set objWord = CreateObject("word.application")
Dim arr, i As Long
Dim strTemp As String
strTemp = "试室安排考生说明" & vbCr
arr = Range("a1").CurrentRegion
With objWord
.Documents.Add
For i = LBound(arr) + 1 To UBound(arr)
strTemp = strTemp & "第 " & arr(i, 1) & " 教室:" & arr(i, 2) & vbCr
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
.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "\" & Format(Date, "yyyymmddhhnn") & ".doc", FileFormat:=0
MsgBox .ActiveDocument.FullName
.ActiveDocument.Close False
.Quit
End With
End Sub