首页 > 其他 > 详细

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

时间:2014-04-14 20:36:21      阅读:667      评论:0      收藏:0      [点我收藏+]

‘ 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


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

VBS 读取excel内容并写入到文本文件,布布扣,bubuko.com

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

原文:http://blog.csdn.net/xinke453/article/details/23663905

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!