我有一个创建 3 个日志的工作簿。在关闭之前,我需要将这三张纸复制到一个新的工作簿中,然后我需要两个工作簿来保存并关闭它们自己。我已经了解了下面的代码,现在当我尝试运行该模块时,它会打开宏窗口并且不会运行。我确实将其存储在 ThisWorkbook 中。任何输入将不胜感激。
Mary
Option Explicit
Private Sub BeforeClose(Cancel As Boolean)
'Save worksheets to new workbook
Dim strSaveName As String
Dim DstFile As String 'destination File name
Dim DataWorkbook As Workbook
'Unhide Worksheets
Set DataWorkbook = ActiveWorkbook
DataWorkbook.Sheets("Service Change Log").Visible = True
DataWorkbook.Sheets("Transaction Log").Visible = True
DataWorkbook.Sheets("Call Initiation Log").Visible = True
ChDir "P:\CSR Rollback Tool\Test"
strSaveName = Replace(Application.UserName, ",", "")
'Copy Sheets
Sheets(Array("Service Change Log", "Transaction Log", "Call Initiation Log")).Copy
'Hide Worksheets
Sheets("Service Change Log").Visible = False
Sheets("Transaction Log").Visible = False
Sheets("Call Initiation Log").Visible = False
'Close Worksheet
MsgBox "P:\CSR Rollback Tool\" & strSaveName & Format(Now(), "yyyymmdd hh-mm") & ".xlsx"
Application.DisplayAlerts = False
DstFile = "P:\CSR Rollback Tool\test\" & strSaveName & Format(Now(), "yyyymmdd hh-mm") & ".xlsx"
Workbooks(DstFile).Close SaveChanges:=True
DataWorkbook.Close Save:=True
End Sub