VBS 读取excel内容并写入到文本文件


' we can pass the excel file name and worksheet as the parameter and using Wscript.Arguments to use it in the script

if(Wscript.Arguments.Count<3) then
 msgbox "The count of Arguments is "&Wscript.Arguments.Count
 'Quit VBS script
 'Wscript.Quit
End if


Set oExcel=CreateObject("excel.application")
Set oWorkBook=oExcel.Workbooks.Open("C:\Users\lude\Downloads\Hypo Case\Basic Property.xls")
'use the worksheet "Prop_Methods"
Set oSheet=oWorkBook.Sheets("Prop_Methods")

'Get the used range
'Set Sheet = oExcel.Worksheets("Prop_Methods").UsedRange

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.Close
' Read=1 Write=2 Append =8
Set a = fs.OpenTextFile("c:\testfile.txt", 8,false)


‘we can write more value to the text file by using loop

value=oSheet.cells(4,2)
a.WriteLine(value)
value=osheet.cells(5,2)
a.WriteLine(value)
value=osheet.cells(6,2)
a.WriteLine(value)
a.Close

Set oSheet=Nothing 
oExcel.Quit


现在可以根据自己的需要修改或扩展脚本实现更丰富的功能

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值