- Sub CopyModule()
- Dim strModuleName As String
- Dim strPath as String
- Dim xlBook As Excel.Workbook
- strPath = "D:/"
- strModuleName = strPath & "MY_MODULE" & ".bas"
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- '导出模块
- ThisWorkbook.VBProject.VBComponents(MODULE_NAME).Export (strModuleName)
- Set xlBook = Workbooks.Add
- '新的Workbook中导入模块
- xlBook.VBProject.VBComponents.Import (strModuleName)
- xlBook.Close savechanges:=True, Filename:= strPath & "NewBook.xls"
- '删除模块文件
- Kill (strModuleName)
- End Sub
这段代码生成EXCEL2007还有点问题,需要改进