标题: [原创] vbs获取excel表中的单元格内容 [打印本页]
作者: batman 时间: 2009-4-4 23:45 标题: vbs获取excel表中的单元格内容
要测试请下载附件,代码及注释如下:- '获取excel表单元格内容,made by batman
- dim hang,lie,counter,counter1,choice '声明变量
- on error resume next '忽略错误
- '设置对象
- set wshshell=createobject ("wscript.shell") '
- path=wshshell.currentdirectory
- set objexcel=createobject ("excel.application")
- set objworks=objexcel.workbooks.open (path&"\test.xls")
- objexcel.worksheets(1).activate
- objexcel.visible=true '设置工作表可见,可去掉此句
- '获取工作表有效总行列数
- counter=0
- do
- counter=counter+1
- loop until objexcel.cells(1,counter).value=""
- lie=counter-1:counter=0
- do
- counter=counter+1
- loop until objexcel.cells(counter,1).value=""
- hang=counter-1
- '查询由输入指定的单元格内容
- do
- counter=inputbox("请输入要查询的行,格式如1,"&vbcrlf&vbcrlf&"输入值应小于"& hang+1&":")
- if counter<>false then
- counter1=inputbox("请输入要查询的列,格式如1,"&vbcrlf&vbcrlf&"输入值应小于"& lie+1&":")
- if counter1<>false then wsh.echo "查询结果:"&vbcrlf&vbcrlf&objexcel.cells(int(counter),int(counter1)).value
- end if
- choice=msgbox ("请问是否继续查询",vbyesno)
- loop until choice=vbno
- objworks.close
- objexcel.quit
- '清空对象,释放内存
- set objworks=nothing
- set objexcel=nothing
- set wshshell=nothing
复制代码
作者: zqz0012005 时间: 2009-4-5 07:41
以前用过。
http://bbs.verybat.org/viewthrea ... romuid=37#pid168380
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |