YellowLabPro
10-04-2007, 12:16 AM
How to properly cancel a Sub?
I want to exit a sub upon selecting the cancel button or the upper right hand "X", the close button.
Currently I am receiving a run time error 1004.
Method SaveAs of object _Workbook Failed.
Pertinent Code:
fname = InputBox("File Name Saved", "Enter File Name to Save As", ThisWorkbook.Name _
& Chr(32) & Format(Date, "m-dd-yy"))
'emailtitle = Left(ThisWorkbook.Name, Find(".", ThisWorkbook.Name, 1) - 1)
emailtitle = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & " Orders"
'=LEFT(I233,FIND(".",I233,1)-1)
Range("A5:AF133").Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Columns("A:A").ColumnWidth = 2
Columns("B:E").EntireColumn.AutoFit
Columns("F:J").ColumnWidth = 11
Columns("K:AF").EntireColumn.AutoFit
Rows("1:6").RowHeight = 14.25
ActiveWorkbook.Names.Add Name:="TotalRow", RefersToR1C1:="=Sheet1!R133C1:R133C33"
Application.CutCopyMode = False
For x = Range("TotalRow").Row - 1 To 15 Step -1
Range("C" & x).EntireRow.Hidden = Len(Range("C" & x)) = 0
Next x
[b12].Select
Columns("B").ColumnWidth = 25
'Code Debugs Here
ActiveWorkbook.SaveAs Filename:=sPath & fname & ".xls"
I want to exit a sub upon selecting the cancel button or the upper right hand "X", the close button.
Currently I am receiving a run time error 1004.
Method SaveAs of object _Workbook Failed.
Pertinent Code:
fname = InputBox("File Name Saved", "Enter File Name to Save As", ThisWorkbook.Name _
& Chr(32) & Format(Date, "m-dd-yy"))
'emailtitle = Left(ThisWorkbook.Name, Find(".", ThisWorkbook.Name, 1) - 1)
emailtitle = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & " Orders"
'=LEFT(I233,FIND(".",I233,1)-1)
Range("A5:AF133").Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Columns("A:A").ColumnWidth = 2
Columns("B:E").EntireColumn.AutoFit
Columns("F:J").ColumnWidth = 11
Columns("K:AF").EntireColumn.AutoFit
Rows("1:6").RowHeight = 14.25
ActiveWorkbook.Names.Add Name:="TotalRow", RefersToR1C1:="=Sheet1!R133C1:R133C33"
Application.CutCopyMode = False
For x = Range("TotalRow").Row - 1 To 15 Step -1
Range("C" & x).EntireRow.Hidden = Len(Range("C" & x)) = 0
Next x
[b12].Select
Columns("B").ColumnWidth = 25
'Code Debugs Here
ActiveWorkbook.SaveAs Filename:=sPath & fname & ".xls"