|
我在word里设了窗体域,用来接收从ACCESS里传过来的数据。
我也是照着例子写的代码,却发现,在我这程序里,代码好多好长,不知能否优化一下。如果优化,又该怎么优化呢?
代码如下:
Set n = CreateObject("word.application")
n.Visible = False
DoCmd.Hourglass True
DoEvents
n.Documents.Open FileName:=mobanPath & "\" & "2上模P1.doc" '打开模板位置下的指定文件
n.Documents("2上模P1.doc").saveas FileName:=strgyName, Password:=""
n.Documents(strgyName).FormFields("wtxtpinghao").Result = Me.txtpinghao '品号
'表头
n.Documents(strgyName).FormFields("wtxtbC0").Result = Me.txtbC '上托长
n.Documents(strgyName).FormFields("wtxtbK0").Result = Me.txtbK '上托宽
n.Documents(strgyName).FormFields("wtxtbH0").Result = Me.txtbH '上托厚
n.Documents(strgyName).FormFields("wtxtz").Result = Me.txtZ '上托厚
'--------------------------------------------------------------------------------------------------------
'表
n.Documents(strgyName).FormFields("wtxtShubei").Result = Me.txtshu '备料
n.Documents(strgyName).FormFields("wtxtShub1").Result = Me.txtshu '刨
n.Documents(strgyName).FormFields("wtxtShup1").Result = Me.txtshu '平磨
n.Documents(strgyName).FormFields("wtxtShuh1").Result = Me.txtshu '横铣
n.Documents(strgyName).FormFields("wtxtShut1").Result = Me.txtshu '钳
n.Documents(strgyName).FormFields("wtxtShuhua").Result = Me.txtshu '划
n.Documents(strgyName).FormFields("wtxtShut2").Result = Me.txtshu '钳
n.Documents(strgyName).FormFields("wtxtShul").Result = Me.txtshu '立铣
n.Documents(strgyName).FormFields("wtxtShut3").Result = Me.txtshu '钳
n.Documents(strgyName).FormFields("wtxtShub2").Result = Me.txtshu '刨
n.Documents(strgyName).FormFields("wtxtShuh2").Result = Me.txtshu '横铣
n.Documents(strgyName).FormFields("wtxtShut4").Result = Me.txtshu '钳
n.Documents(strgyName).FormFields("wtxtShup2").Result = Me.txtshu '平磨
'--------------------------------------------------------------------------------------------------------
'表尾
n.Documents(strgyName).FormFields("wtxtGongYi").Result = Me.cbogongyi
' n.Documents(strgyName).FormFields("wtxtShenhe").Result = Me.cboShenhe
n.Documents(strgyName).FormFields("wtxtriqi").Result = Format(Me.txtriqi, "yy年mm月dd日")
n.Documents(strgyName).FormFields("wtxtye").Result = Me.txtYe
n.Visible = True
DoCmd.Hourglass False |
|