private sub commandbutton1_click() dim app as excel.application dim xlapp as variant dim xlworkbooks as workbooks dim myfile, mypath, myname mypath = "d:/temp" myname = dir(mypath & "/" & "*.xls") do while myname <> "" ' 开始循环。
set xlapp = getobject(mypath & "/" & myname) set w_sheets = xlapp.worksheets xlapp.application.displayalerts = false '不显示警告 xlapp.worksheets("sheet2").delete workbooks(myname).save xlapp.application.displayalerts = true xlapp.application.visible = true workbooks(myname).close myname = dir ' 查找下一个目录。 loop end sub