我想写一段VBA,能打开XLS文件并且删除打开文件的宏代码,如何实现呢?
------解决方案--------------------------------------------------------
- VB code
Sub Macro1()'引用 Microsoft Visual Basic For Application Extensibility 5.3 Dim vbc As VBComponent, a As Shape, sh As Worksheet Filename = Application.GetOpenFilename(FileFilter:="Excel 工作簿文件 (*.xls),*.xls", Title:="请选择文件") If TypeName(Filename) = "Boolean" Then Exit Sub Application.ScreenUpdating = False With Workbooks.Open(Filename) For Each sh In .Sheets For Each a In sh.Shapes a.Delete Next Next For Each vbc In Application.ActiveWorkbook.VBProject.VBComponents Select Case vbc.Type Case 1, 2, 3 With Application.VBE.ActiveVBProject.VBComponents .Remove .Item(vbc.Name) '删除模块、类模块、窗体 End With Case Else vbc.CodeModule.DeleteLines 1, vbc.CodeModule.CountOfLines '删除工作表或Thisworkbook代码区代码 End Select Next .Close True End With Application.ScreenUpdating = True MsgBox "ok"End Sub