首先引入Microsoft Word Object Library的引用库("工程"中的"引用")
Dim mydoc As Word.Document
set mydoc=New Word.Document
mydoc.ActiveWindow.Selection.TypeText "Good!"
当运行了上面的语句后将会打开一个Word文档并在其中显示"Good!"
Dim mydoc As Word.Document
set mydoc=New Word.Document
mydoc.ActiveWindow.Selection.TypeText "Good!"
当运行了上面的语句后将会打开一个Word文档并在其中显示"Good!"
Dim workbook As Object
Dim worksheet As ObjectScreen.MousePointer = 11On Error GoTo DeleteFileMsgIf Dir(App.Path & "\temp.xls") <> "" Then Kill App.Path & "\temp.xls"
''拷贝相应文件到一个临时文件 temp.xls
FileCopy App.Path & "\婚姻状况证明.xls", App.Path & "\temp.xls"
On Error GoTo OtherErrSet excel = CreateObject("excel.application")
Set workbook = excel.Workbooks.Open(App.Path & "\temp.xls")
Set worksheet = workbook.ActiveSheetOn Error GoTo Guanbi''向表格中填数据 Call sub婚姻证明(worksheet)If bPreview Then
excel.Visible = True
excel.WindowState = xlMaximized
worksheet.PrintPreview
Else
worksheet.PrintOut
End IfGuanbi: '========Guanbi============workbook.Saved = True
workbook.Close
excel.Quit
Set excel = Nothing
Screen.MousePointer = 0Exit Sub
DeleteFileMsg:
Dim msg As String
msg = "错误:" & vbNewLine
msg = msg & vbNewLine & " 1、请删除文件: " & App.Path & "\temp.xls"
msg = msg & vbNewLine & " 2、请检查所需的模板文件是否存在或已被打开(如果打开,请关闭;如果不能关闭,请重新启动Windows)"
MsgBox msg, vbInformation + vbOKOnly
Screen.MousePointer = 0Exit Sub
OtherErr:
MsgBox Err.Number & Err.Description
Screen.MousePointer = 0
End SubPrivate Sub sub婚姻证明(ByVal ws As worksheet)With ws
.Cells(4, 4) = hyzm.序号
.Cells(7, 3) = hyzm.姓名
.Cells(8, 3) = hyzm.性别
.Cells(9, 3) = hyzm.出生日期
.Cells(10, 3) = hyzm.婚姻状况
.Cells(11, 3) = hyzm.对方姓名
.Cells(12, 3) = hyzm.对方单位
.Cells(13, 3) = hyzm.血亲关系
.Cells(14, 3) = hyzm.登记机关
.Cells(15, 3) = hyzm.备注左
.Cells(17, 3) = hyzm.出证员
.Cells(18, 3) = hyzm.负责人
.Cells(19, 3) = hyzm.填证日期
End WithEnd Sub