A
Andibevan
I have the following code that opens up a creates a copy of the open
workbook and then removes specific sheets and lines from the copy. It then
sends attaches the workbook to an e-mail.
I am having problems with the line wbCopy.Close - when it gets there it
throughs a 'Subscript out of range error' and then Excel crashes.
Any ideas why?
TIA
Andi
Debug.Print "Now = " & Now()
Dim wbCopy As Excel.Workbook
Dim sCRNT_Workbook As Excel.Workbook: Set sCRNT_Workbook =
ActiveWorkbook '.Name
'#####Temp Name#####
Dim sTime As String
Dim sSaveAs As String
sTime = Int(Format(Now, "hh"))
sSaveAs = Format(Now, "dd") & OrdinalSuffix(Day(Now)) & " " &
Format(Now, "mmmm") & " - " & sTime & "00.xls"
sSaveAs = "SMV Project Log_Lite_" & sSaveAs
' Debug.Print "sSaveAs = " & sSaveAs
Dim sBookPath As String: sBookPath = ActiveWorkbook.path & "\" &
sSaveAs
ActiveWorkbook.SaveCopyAs sBookPath
'#################################
' OPEN THE COPIED WORKBOOK
Set wbCopy = Workbooks.Open(sBookPath)
'wbCopy.Application.Visible = False
wbCopy.Application.ScreenUpdating = False
wbCopy.Application.Calculation = xlCalculationManual
' REMOVE UNWANTED ROWS AND SHEETS
DeleteUnwantedSheets sCRNT_Workbook, wbCopy
RemoveUnwantedRows wbCopy, "Project Log Form",
(Find_Col_Let("Project Log Form", 8, "Status: Open Closed")), 9, "CLOSED"
RemoveUnwantedRows wbCopy, "Risk Management Plan",
(Find_Col_Let("Risk Management Plan", 6, "Risk Status (Open, Mitigated,
Closed)")), 10, "CLOSED"
RemoveUnwantedRows wbCopy, "Change Register",
(Find_Col_Let("Change Register", 8, "Review")), 7, "N"
DeleteModules wbCopy
'wbCopy.Application.Visible = True
wbCopy.Save
wbCopy.Application.ScreenUpdating = True
wbCopy.Application.Calculation = xlCalculationAutomatic
wbCopy.Application.Calculate
'wbCopy.Close
'WaitTilClose wbCopy.Name
Mail_workbook_Outlook sCRNT_Workbook, wbCopy.FullName
wbCopy.Close
Set wbCopy = Nothing
Debug.Print "Now = " & Now()
workbook and then removes specific sheets and lines from the copy. It then
sends attaches the workbook to an e-mail.
I am having problems with the line wbCopy.Close - when it gets there it
throughs a 'Subscript out of range error' and then Excel crashes.
Any ideas why?
TIA
Andi
Debug.Print "Now = " & Now()
Dim wbCopy As Excel.Workbook
Dim sCRNT_Workbook As Excel.Workbook: Set sCRNT_Workbook =
ActiveWorkbook '.Name
'#####Temp Name#####
Dim sTime As String
Dim sSaveAs As String
sTime = Int(Format(Now, "hh"))
sSaveAs = Format(Now, "dd") & OrdinalSuffix(Day(Now)) & " " &
Format(Now, "mmmm") & " - " & sTime & "00.xls"
sSaveAs = "SMV Project Log_Lite_" & sSaveAs
' Debug.Print "sSaveAs = " & sSaveAs
Dim sBookPath As String: sBookPath = ActiveWorkbook.path & "\" &
sSaveAs
ActiveWorkbook.SaveCopyAs sBookPath
'#################################
' OPEN THE COPIED WORKBOOK
Set wbCopy = Workbooks.Open(sBookPath)
'wbCopy.Application.Visible = False
wbCopy.Application.ScreenUpdating = False
wbCopy.Application.Calculation = xlCalculationManual
' REMOVE UNWANTED ROWS AND SHEETS
DeleteUnwantedSheets sCRNT_Workbook, wbCopy
RemoveUnwantedRows wbCopy, "Project Log Form",
(Find_Col_Let("Project Log Form", 8, "Status: Open Closed")), 9, "CLOSED"
RemoveUnwantedRows wbCopy, "Risk Management Plan",
(Find_Col_Let("Risk Management Plan", 6, "Risk Status (Open, Mitigated,
Closed)")), 10, "CLOSED"
RemoveUnwantedRows wbCopy, "Change Register",
(Find_Col_Let("Change Register", 8, "Review")), 7, "N"
DeleteModules wbCopy
'wbCopy.Application.Visible = True
wbCopy.Save
wbCopy.Application.ScreenUpdating = True
wbCopy.Application.Calculation = xlCalculationAutomatic
wbCopy.Application.Calculate
'wbCopy.Close
'WaitTilClose wbCopy.Name
Mail_workbook_Outlook sCRNT_Workbook, wbCopy.FullName
wbCopy.Close
Set wbCopy = Nothing
Debug.Print "Now = " & Now()