高手看一下,关于VB调用Execel的问题。

wsmall 2003-10-18 08:56:37
我用VB调用Execel生成报表,在2000、xp下面都没有问题,但是到了98下面出现问题了。执行程序后,我发现能够通过程序打开我的模板文件,但是上面没有写数据,我在98下面分步调试的时候,往execel中写数据的代码也执行了,但是就是没有数据,急呀。
下面是我的调用execel的代码:
Dim VBExcel As Excel.Application
Dim xlbook As Excel.Workbook '定义Excel工作簿对象
Dim xlsheet As Excel.Worksheet '定义Excel工作表对象
Set VBExcel = CreateObject("excel.application")
VBExcel.Visible = True
'根据操作人员是否需要见到Excel此处可设为TRUE 或FALSE
Dim strPath As String
strPath_s = App.Path & "\xls\mod_d.xls"
strPath_d = App.Path & "\xls\temp.xls"
'On Error Resume Next
FileCopy strPath_s, strPath_d
Set xlbook = VBExcel.Workbooks.Open(strPath_d)
'ExcelFile为事先设计好的Excel模板文件 (包括路径)
Set xlsheet = xlbook.Worksheets("test1")
'Salary 为Excel模板工作表的名字
xlsheet.Activate

下面是部分写数据的代码:
xlsheet.Cells(7, 4) = CSng(rs_f("wgdl4")) + CSng(rs_f("wgdl5"))
xlsheet.Cells(7, 5) = CSng(rs_f_s("wgdl4_s")) + CSng(rs_f_s("wgdl5_s"))

xlsheet.Cells(8, 4) = CSng(rs_f("gf4")) + CSng(rs_f("gf5"))
xlsheet.Cells(8, 5) = CSng(rs_f_s("gf4_s")) + CSng(rs_f_s("gf5_s"))

xlsheet.Cells(9, 4) = CSng(rs_f("dg4")) + CSng(rs_f("dg5"))
xlsheet.Cells(9, 5) = CSng(rs_f_s("dg4_s")) + CSng(rs_f_s("dg5_s"))

xlsheet.Cells(10, 4) = CSng(rs_f("pd4")) + CSng(rs_f("pd5"))
xlsheet.Cells(10, 5) = CSng(rs_f_s("pd4_s")) + CSng(rs_f_s("pd5_s"))

xlsheet.Cells(11, 4) = fdl1 - CSng(rs_b("gycb4")) - CSng(rs_b("gycb5"))
xlsheet.Cells(11, 5) = fdl2 - CSng(rs_b_s("gycb4_s")) - CSng(rs_b_s("gycb5_s"))

请高手帮帮忙呀。
...全文
30 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsmall 2003-10-20
  • 打赏
  • 举报
回复
应该不是,都是用的2000
wishesyou 2003-10-19
  • 打赏
  • 举报
回复
会不会是引用excel的版本不对?
wsmall 2003-10-18
  • 打赏
  • 举报
回复
up
wsmall 2003-10-18
  • 打赏
  • 举报
回复
没有问题!在XP和2000下都没有问题!98运行也不报错!
hhjjhjhj 2003-10-18
  • 打赏
  • 举报
回复
代码看来没问题,是不是你的函数rs_x的问题
xlsheet.Cells(7, 4)=12345 这样试试

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧