以下是俺以前做的一个绩效管理模块中的生成上报表子模块,没有仔细修改,仅供参考! 思路很简单,生成一个新的工作簿,然后另存为当前工作簿同目录下的一个文件,然后再将需要的工作表从当前工作簿中拷贝过去,最后再删除新增工作簿中的所有VBA。 PS:宏安全性中,可行发行商中须勾选 信任对于VB项目的访问 Sub S_生成上报表() Application.EnableEvents = False Application.ScreenUpdating = False Application.DisplayAlerts = False this_wb_name = ThisWorkbook.Name bm ="备份" p_ath = ThisWorkbook.Path & "\" : f_name = "绩效统计报表_" & bm & ".xls" Workbooks.Add On Error Resume Next ActiveWorkbook.SaveAs Filename:=p_ath & f_name On Error GoTo 0 new_wb_name = f_name With Workbooks(this_wb_name) Dim shet As String, i As Integer Application.DisplayAlerts = False For Each sht In .Sheets sht.Copy after:=Workbooks(new_wb_name).Sheets(3) Next sht End With Windows(new_wb_name).Activate For Each sht In Workbooks(this_wb_name).Sheets: sht.Visible = xlSheetVisible: Next Workbooks(Workbooks.Count).Worksheets("Sheet3").Delete Workbooks(Workbooks.Count).Worksheets("Sheet2").Delete Workbooks(Workbooks.Count).Worksheets("Sheet1").Delete With Workbooks(Workbooks.Count) '以下开始删除VBA代码 Dim vbcCom, Vbc Set vbcCom = .VBProject.VBComponents For Each Vbc In vbcCom If Vbc.Name Like "Sheet*" Or Vbc.Name Like "This*" Then Vbc.CodeModule.DeleteLines 1, Vbc.CodeModule.CountOfLines Else vbcCom.Remove (Vbc) End If Next Vbc .Save .Close End With'删除结束 Application.EnableEvents = True If MsgBox("完成上报表制作,文件保存在" & p_ath & "中!" & Chr(10) & Chr(10) & "现在需要打开上报文件吗?", vbYesNo, "请选择:") = 6 Then Application.Workbooks.Open p_ath & new_wb_name Err.Clear Application.ScreenUpdating = True End Sub
|