7,763
社区成员
发帖
与我相关
我的任务
分享
Private Sub printord_Click()
'按照指定格式打印订单文档Contract.doc
Dim wdoc As Object '定义WORD文件对象
Dim wapp As Object '定义word应用程序
Dim mytable As Object
Dim arow As Object
Dim wordfile As String
wordfile = "Contract.doc" '文档名称
'If Dir(wordfile) = "" Then '判断文件是否存在
'MsgBox "打印文件Contract.doc丢失,请与管理员联系"
'Exit Sub
'End If
'启动应用程序
Set wapp = CreateObject("Word.Application") '王伟修改
wapp.Visible = True
'打印过程可见
'打开Contract.doc文件
Set wdoc = wapp.Documents.Open(Apppath + "\" + wordfile, ReadOnly:=True, Revert:=True)
'读写订单编号
wdoc.Tables(1).Cell(2, 1).Range.Delete
wdoc.Tables(1).Cell(2, 1).Range.InsertAfter "订单编号:" + Trim(orderID.Caption)
'订单打印时间
wdoc.Tables(1).Cell(2, 2).Range.Delete
wdoc.Tables(1).Cell(2, 2).Range.InsertAfter "打印时间:" + Trim(str(Now))
'输出订单信息
wdoc.Tables(2).Cell(1, 2).Range.InsertAfter Trim(newtime.Text) '创建日期
wdoc.Tables(2).Cell(1, 4).Range.InsertAfter Trim(contime.Text) '交货日期
wdoc.Tables(2).Cell(2, 2).Range.InsertAfter Trim(sample.Text) '样品类型
wdoc.Tables(2).Cell(2, 4).Range.InsertAfter Trim(total.Text) '合计
wdoc.Tables(2).Cell(3, 2).Range.InsertAfter Trim(price.Text) '单价
wdoc.Tables(2).Cell(3, 4).Range.InsertAfter Trim(amount) '数量
wdoc.Tables(2).Cell(4, 2).Range.InsertAfter Trim(discount.Text) '折扣
wdoc.Tables(2).Cell(4, 4).Range.InsertAfter Trim(earnestMoney.Text) '已交定金
wdoc.Tables(2).Cell(5, 2).Range.InsertAfter Trim(ordernote.Text) '备注
'商家信息
shop.selectinfo
wdoc.Tables(3).Cell(1, 2).Range.InsertAfter Trim(rs.Fields(0)) '店名
wdoc.Tables(3).Cell(1, 4).Range.InsertAfter Trim(rs.Fields(1)) '联系人
wdoc.Tables(3).Cell(2, 2).Range.InsertAfter Trim(rs.Fields(2)) '座机
wdoc.Tables(3).Cell(2, 4).Range.InsertAfter Trim(rs.Fields(3)) '手机
wdoc.Tables(3).Cell(3, 2).Range.InsertAfter Trim(rs.Fields(4)) '邮箱
wdoc.Tables(3).Cell(3, 4).Range.InsertAfter Trim(rs.Fields(5)) 'qq
wdoc.Tables(3).Cell(4, 2).Range.InsertAfter Trim(rs.Fields(6)) '地址
CloseRs
'客户信息
wdoc.Tables(4).Cell(1, 2).Range.InsertAfter Trim(customerID.Caption) '客户编号
wdoc.Tables(4).Cell(1, 4).Range.InsertAfter Trim(customername.Text) '客户姓名
wdoc.Tables(4).Cell(2, 2).Range.InsertAfter Trim(customersex.Text) '性别
wdoc.Tables(4).Cell(2, 4).Range.InsertAfter Trim(customerpost.Text) '邮编
wdoc.Tables(4).Cell(3, 2).Range.InsertAfter Trim(customerIDCard.Text) '身份证号
wdoc.Tables(4).Cell(3, 4).Range.InsertAfter Trim(name3d.Text) '相关文件
wdoc.Tables(4).Cell(4, 2).Range.InsertAfter Trim(customertel.Text) '联系电话
wdoc.Tables(4).Cell(4, 4).Range.InsertAfter Trim(customerpost.Text) '邮编
wdoc.Tables(4).Cell(5, 2).Range.InsertAfter Trim(customeraddr.Text) '地址
wdoc.Tables(4).Cell(6, 2).Range.InsertAfter Trim(customercom.Text) '工作单位
wdoc.Tables(4).Cell(7, 2).Range.InsertAfter Trim(customernote.Text) '备注
Cancel:
Set wdoc = Nothing '清空文件对象
Set wapp = Nothing '清空应用程序对象
End Sub
Dim wdoc As Object '定义WORD文件对象
Dim mytable As Object
Dim arow As Object
Dim wordfile As String
On Error GoTo ErrorHandler:
wordfile = "Contract.doc" '文档名称
Set wapp = CreateObject("Word.Application")
Set wapp = New Word.Application
wapp.Visible = True
Set wdoc = wapp.Documents.Open(Apppath + "\" + wordfile, ReadOnly:=True, Revert:=True)
。。。。。。。。。
'Set wdoc = Nothing '清空文件对象
'Set wapp = Nothing '清空应用程序对象
ErrorHandler:
If InStr(1, Err.Description, "ActiveX component can't create object") <> 0 Then
MsgBox "请检查是否装有Word应用程序?" + Chr(10) + Chr(13) + "打印订单不能进行!", vbOKOnly + vbCritical, "错误提示"
Exit Sub
End If
MsgBox Err.Description
Set wdoc = Nothing '清空文件对象
Set wapp = Nothing '清空应用程序对象
ReadOnly:=True ?