网上考的但看不懂,谢谢解释一下,我是菜鸟
运行时出现“未定义类”
我按这个步骤做:
(1)建word模板文档
(2)在vb6.0中将下面的代码输入
(3)是不是还要自己建个access数据表,再定义字符能否推荐一本有下列例子的教材,谢谢
用vb+word模版+数据库来制作格式合同的方法
概述:在应用程序中经常有定制格式报表的需要,如打印合同、货物清单、备忘录等等,使用第三方报表软件可以实现但是比较繁琐,实际上利用word的自动化编程,使用vba可以完成类似的功能,而且很实用。
步骤一、
word模版制作:
在第一行是合同标题 " 【书签1合同标题xxxxxxxx合同】"
第二行
******************************
合同编号: 【书签2合同编号】
签约单位: 【书签3签约单位】
签约地址: 【书签4签约地址】
签约日期: 【书签5签约日期】.....表格第一行 '表格第一行第一列中插入 书签4
表格第二行
'实现代码如下
dim cn as new adodb.connection
dim adors as new adodb.recordset
dim wordtemps as new word.application
private sub form_load()
if cn.state = 1 then
cn.close
end if
cn.cursorlocation = aduseclient
cn.open "provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\db1.mdb"
end sub
'开始导出数据
private sub command1_click()
dim strsql as string
dim rec as integer
dim i as integer
wordtemps.documents.add app.path + "\货物合同.doc", false
wordtemps.selection.goto wdgotobook, , , "合同标题"
wordtemps.selection.typetext “关于冬季货物的成交合同”
wordtemps.selection.goto wdgotobook, , , "合同编号"
wordtemps.selection.typetext “2004000001”
wordtemps.selection.goto wdgotobook, , , "签约单位"
wordtemps.selection.typetext “宏大科技公司,天天科技公司”
wordtemps.selection.goto wdgotobook, , , "签约地址"
wordtemps.selection.typetext “北京中关村大厦”
wordtemps.selection.goto wdgotobook, , , "签约时间"
wordtemps.selection.typetext fromat(now, "yyyy-mm-dd")
strsql = "select * from matrixs"
adors.open strsql, cn, adopenkeyset, adlockoptimistic
rec = adors.recordcount
if rec < 1 then
msgbox "无商品记录!", vbokonly, "提示"
adors.close
exit sub
else
adors.movefirst
wordtemps.selection.goto wdgotobook, , , "货物清单"
for i = 1 to rec
wordtemps.selection.typetext adors!名称
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!数量
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!规格
adors.movenext
if adors.eof = false then
wordtemps.selection.insertrowsbelow 1 '表格换行
end if
next i
adors.close
wordtemps.visible = true '显示word窗口
end if
end sub
作者:soho_andy(冰)
运行时出现“未定义类”
我按这个步骤做:
(1)建word模板文档
(2)在vb6.0中将下面的代码输入
(3)是不是还要自己建个access数据表,再定义字符能否推荐一本有下列例子的教材,谢谢
用vb+word模版+数据库来制作格式合同的方法
概述:在应用程序中经常有定制格式报表的需要,如打印合同、货物清单、备忘录等等,使用第三方报表软件可以实现但是比较繁琐,实际上利用word的自动化编程,使用vba可以完成类似的功能,而且很实用。
步骤一、
word模版制作:
在第一行是合同标题 " 【书签1合同标题xxxxxxxx合同】"
第二行
******************************
合同编号: 【书签2合同编号】
签约单位: 【书签3签约单位】
签约地址: 【书签4签约地址】
签约日期: 【书签5签约日期】.....表格第一行 '表格第一行第一列中插入 书签4
表格第二行
'实现代码如下
dim cn as new adodb.connection
dim adors as new adodb.recordset
dim wordtemps as new word.application
private sub form_load()
if cn.state = 1 then
cn.close
end if
cn.cursorlocation = aduseclient
cn.open "provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\db1.mdb"
end sub
'开始导出数据
private sub command1_click()
dim strsql as string
dim rec as integer
dim i as integer
wordtemps.documents.add app.path + "\货物合同.doc", false
wordtemps.selection.goto wdgotobook, , , "合同标题"
wordtemps.selection.typetext “关于冬季货物的成交合同”
wordtemps.selection.goto wdgotobook, , , "合同编号"
wordtemps.selection.typetext “2004000001”
wordtemps.selection.goto wdgotobook, , , "签约单位"
wordtemps.selection.typetext “宏大科技公司,天天科技公司”
wordtemps.selection.goto wdgotobook, , , "签约地址"
wordtemps.selection.typetext “北京中关村大厦”
wordtemps.selection.goto wdgotobook, , , "签约时间"
wordtemps.selection.typetext fromat(now, "yyyy-mm-dd")
strsql = "select * from matrixs"
adors.open strsql, cn, adopenkeyset, adlockoptimistic
rec = adors.recordcount
if rec < 1 then
msgbox "无商品记录!", vbokonly, "提示"
adors.close
exit sub
else
adors.movefirst
wordtemps.selection.goto wdgotobook, , , "货物清单"
for i = 1 to rec
wordtemps.selection.typetext adors!名称
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!数量
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!规格
adors.movenext
if adors.eof = false then
wordtemps.selection.insertrowsbelow 1 '表格换行
end if
next i
adors.close
wordtemps.visible = true '显示word窗口
end if
end sub
作者:soho_andy(冰)
解决方案 »
- 菜的快晕了
- 如何让WORD在OLE中翻页,或者有其他的方法也可以~
- 如何选中text场的文字,就是选中文字,并反显
- Crystal report8.5 中:为什么text中只能显示255个字?
- 怎样用ADOX创建一个带密码保护的数据库?
- qbasic界面在显示器全屏,但投影不能全屏。。。。。。。。
- 急,在线等。要取年月日及小时分钟,在access数据库中应存成什么型的
- 求救:數據直接寫入到DataReport
- 上个问题已经给分,再来一个....
- 用OLe和formula one6控件 打印(制作)excel报表各有什么优缺点>
- matcom4.5转换function成VB可调用的dll的问题
- SendMessage(WM_GETHOTKEY)怎么用?
------------------
IOAS:易学易用、灵活自由、个人免费使用的办公系统速成工具。
详情请访问:www.ioas.net
------------------
后面主要strsql = "select * from matrixs"
adors.open strsql, cn, adopenkeyset, adlockoptimistic
rec = adors.recordcount
if rec < 1 then
msgbox "无商品记录!", vbokonly, "提示"
adors.close
exit sub
else
adors.movefirst
wordtemps.selection.goto wdgotobook, , , "货物清单"
for i = 1 to rec
wordtemps.selection.typetext adors!名称
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!数量
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!规格
adors.movenext
if adors.eof = false then
wordtemps.selection.insertrowsbelow 1 '表格换行
end if
next i
adors.close
wordtemps.visible = true '显示word窗口
end if
实现数据的写入
概述:在应用程序中经常有定制格式报表的需要,如打印合同、货物清单、备忘录等等,使用第三方报表软件可以实现但是比较繁琐,实际上利用word的自动化编程,使用vba可以完成类似的功能,而且很实用。
步骤一、
word模版制作:注意合同模板的制作,要使用书签的,因为在程序中进行了引用在第一行是合同标题 " 【书签1合同标题xxxxxxxx合同】"
第二行
******************************
合同编号: 【书签2合同编号】
签约单位: 【书签3签约单位】
签约地址: 【书签4签约地址】
签约日期: 【书签5签约日期】.....表格第一行 '表格第一行第一列中插入 书签4
表格第二行
'实现代码如下
定义数据库的链接dim cn as new adodb.connection
dim adors as new adodb.recordset
dim wordtemps as new word.application
private sub form_load()
if cn.state = 1 then
cn.close
end if
cn.cursorlocation = aduseclient
cn.open "provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\db1.mdb"
end sub
'开始导出数据
private sub command1_click()
dim strsql as string
dim rec as integer
dim i as integer
wordtemps.documents.add app.path + "\货物合同.doc", false
wdgotobook就是书签的引用
wordtemps.selection.goto wdgotobook, , , "合同标题"
wordtemps.selection.typetext “关于冬季货物的成交合同”
wordtemps.selection.goto wdgotobook, , , "合同编号"
wordtemps.selection.typetext “2004000001”
wordtemps.selection.goto wdgotobook, , , "签约单位"
wordtemps.selection.typetext “宏大科技公司,天天科技公司”
wordtemps.selection.goto wdgotobook, , , "签约地址"
wordtemps.selection.typetext “北京中关村大厦”
wordtemps.selection.goto wdgotobook, , , "签约时间"
wordtemps.selection.typetext fromat(now, "yyyy-mm-dd")
strsql = "select * from matrixs"
adors.open strsql, cn, adopenkeyset, adlockoptimistic
rec = adors.recordcount
if rec < 1 then
msgbox "无商品记录!", vbokonly, "提示"
adors.close
exit sub
else
adors.movefirst
wordtemps.selection.goto wdgotobook, , , "货物清单"
for i = 1 to rec
wordtemps.selection.typetext adors!名称
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!数量
wordtemps.selection.moveright unit:=wdcharacter, count:=1 '右移一格
wordtemps.selection.typetext adors!规格
adors.movenext
if adors.eof = false then
wordtemps.selection.insertrowsbelow 1 '表格换行
end if
next i
adors.close
wordtemps.visible = true '显示word窗口
end if
end sub