excel宏脚本问题
来源:百度知道 编辑:UC知道 时间:2024/05/25 02:20:10
谢谢2楼的,挺好的办法,试了一下就是子目录里的文件并没有处理,有没有办法将根目录下所有子目录的文件都一次处理掉?要不然文件夹很多的情况下比较麻烦
set ws=createobject("wscript.shell")
path=ws.currentdirectory
set fso=createobject("scripting.filesystemobject")
set folder=fso.getfolder(path)
set files=folder.files
for each file in files
if right(file,3)="xls" then call excel(file)
next
msgbox "操作成功!",48+4096,"系统提示"
sub excel(a)
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(a)
intRow = 1
Do Until objExcel.Cells(intRow,1).Value = ""
h= objExcel.Cells(intRow, 1).Value
objExcel.Cells(intRow, 2).Value=left(h,3)
objExcel.Cells(intRow, 3).Value=mid(h,4,2)
objExcel.Cells(intRow, 4).Value=right(h,2)
intRow = intRow + 1
Loop
objExcel.ActiveWorkbook.Save '保存
objExcel.Quit
end sub
把上面的内容保存成VBS文件,之后把它复制到EXCEL文档的目录下,双击运行即可,连宏也不用了一个文件搞定了。
(强烈建议:请务必在测试后使用!)
已经修改后,发给你了,查收一下。