Saving Workbook Error-Plz help

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I have the following code to automatically save the workbook

Private Sub CommandButton3_Click()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

I get this mesage box:
"A file named "myfilename.xls" already exists in this location, do you want
to replace it?"
I dont want this to come up. is there any way around this? Thanks
 
That was the code in sheet 2, and the code in ThisWorkbook is as follows:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Data").Activate
Columns("A:J").Select

If Selection.EntireColumn.Hidden <> True Then
Selection.EntireColumn.Hidden = True
End If

sheetprot 'subroutine that protects all sheets
ThisWorkbook.Save
ThisWorkbook.Close
End Sub
 
I think this is what your after

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
With ThisWorkbook
.Save
.Close
End With
Application.DisplayAlerts = True
End Sub
 
Back
Top