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