vb读取写入导出excel

  1. test()  
  2. '从"工程"菜单中选择"引用"栏;选择Microsoft Excel 9.0 Object Library(EXCEL2000)  
  3. Dim xlApp As Excel.Application  
  4. Dim xlBook As Excel.Workbook  
  5. Dim xlSheet As Excel.Worksheet  
  6.   
  7. '---------------------操作现有的excel---------------------  
  8. Set xlApp = CreateObject("Excel.Application"'创建EXCEL对象  
  9. Set xlBook = xlApp.Workbooks.Open("c:/sheep.xls"'打开已经存在的EXCEL工件簿文件  
  10. xlApp.Visible = True '设置EXCEL对象可见(或不可见)  
  11. Set xlSheet = xlBook.Worksheets("Sheet1"'设置活动工作表  
  12. xlSheet.Cells(1, 2) = "sssss" '给单元格(row,col)赋值  
  13. s = xlSheet.Cells(2, 2).Value  
  14. xlBook.Close (True'关闭工作簿  
  15. xlApp.Quit '结束EXCEL对象  
  16. Set xlApp = Nothing '释放xlApp对象  
  17. 'xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL启动宏  
  18. 'xlBook.RunAutoMacros (xlAutoClose) '运行EXCEL关闭宏  
  19. '------------------------end------------------------------  
  20.   
  21. '---------------------导出新的excel-------------------------  
  22. Set xlApp = CreateObject("Excel.Application")  
  23. Set xlBook = xlApp.Workbooks.Add   '创建工作簿  
  24. xlApp.Visible = False  
  25. Set xlSheet = xlBook.Worksheets(1) '创建工作表  
  26. xlSheet.Name = "表一" '表名  
  27. xlSheet.Cells(1, 1) = "shshshs"  
  28.   
  29. xlSheet.SaveAs "c:/销售.xls"  
  30. 'xlSheet.SaveAs App.Path & "/销售/" & mystr & ".xls"  
  31. xlBook.Close (True'关闭工作簿  
  32. xlApp.Quit '结束EXCEL对象  
  33. Set xlApp = Nothing '释放xlApp对象  
  34. '-------------------------end-----------------------------  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值