03856me
Active Member
- Joined
- Apr 4, 2008
- Messages
- 297
I have written code to export two tabs and rename the file and do other manipliation to the data which works fine as long as the user chooses Yes or No to the messages, but if they choose cancel after the first Yes, an error comes up. My Yes and No responses are working correctly, just the cancel option that errors out. Can someone help me modify this code to take care of that? or point me where to look.
I am getting a 1004 error at the where indicated below with 'XXXXX and it doesn't close the new file.
Your help is greatly appreciated
I am getting a 1004 error at the where indicated below with 'XXXXX and it doesn't close the new file.
Your help is greatly appreciated
Code:
'================================================
' THiS MACRO DUMPS THE EDIT FILE DATA AND THE TRACT INFO
Sub DumpEdit()
If Range("TractName").Value = "" Then
MsgBox ("Missing File Name - Add through Enter/Edit Tract Info button")
Else
If MsgBox("CAUTION: Do you want to create the Export File now?", vbQuestion + vbYesNo) = vbYes Then
Application.ScreenUpdating = False
ActiveSheet.DisplayPageBreaks = False
Application.StatusBar = "Working....."
'Copies data and hold tabs out of original workbook to a new workbook
Dim DataWorkbook As Workbook
Set DataWorkbook = ActiveWorkbook
Worksheets("data").Visible = True
Worksheets("Hold").Visible = True
DataWorkbook.Sheets(Array("data", "HOLD")).Copy
ChDir "C:\Cruize-New"
On Error GoTo myerror
ActiveWorkbook.SaveAs FileName:="C:\Cruize-New\" & Range("TractName") & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
If ActiveWorkbook.Saved = True Then
ProcessNewFile
Worksheets("data").Visible = False
Worksheets("Hold").Visible = False
Application.ScreenUpdating = True
End If
End If
Application.StatusBar = False
Exit Sub
myerror:
If Err.Number = 1004 Then
Workbooks(2).Activate
ActiveWorkbook.Close
End If
End If
Worksheets("data").Visible = xlSheetVeryHidden
'XXXXX Worksheets("Hold").Visible = xlSheetVeryHidden
MsgBox "Your data WAS NOT exported to a new file!"
End Sub
'===============================================
Sub ProcessNewFile()
Application.ScreenUpdating = False
Sheets("data").Unprotect Password:="test"
Worksheets("data").Select
ActiveSheet.Cells.EntireColumn.Hidden = False
ActiveSheet.Cells.EntireRow.Hidden = False
Range("AB:KN").Delete
Range("Z:Z").Delete
Range("X:X").Delete
Range("V:V").Delete
Range("T:T").Delete
Range("R:R").Delete
Rows("6:7").Select
Selection.EntireRow.Hidden = True
Range("A8").Select
ActiveSheet.Shapes("ReportMenu").Delete
Worksheets("Hold").Select
Sheets("Hold").Unprotect Password:="test"
ActiveSheet.Shapes("Rounded Rectangle 1").Delete
Range("I:J").Delete
Range("B9").Validation.Delete
Range("A1:AC166").Interior.ColorIndex = xlColorIndexNone
ActiveWorkbook.Save
ActiveWorkbook.Close
Worksheets("data").Visible = xlSheetVeryHidden
Worksheets("Hold").Visible = xlSheetVeryHidden
MsgBox "YOUR NEW REPORT HAS BEEN SAVED"
Application.ScreenUpdating = True
End Sub