niyrho
08-24-2008, 05:46 PM
I'm pretty new to VBA. Trying to get a file to automaticly chose a file name and save the workbook when you try to exit it. Its not finding the name or letting me exit. Can anyone tell me whats wrong with my code?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo Exits
Cancel = True
Application.EnableEvents = False
With ActiveSheet
ActiveWorkbook.SaveCopyAs "C:\TimeSheets\" & Format(Worksheets(3).Range("A12"), " yy-mm-dd") & Worksheets(3).Range("H10") & ".xls"
End With
Exits:
Application.EnableEvents = True
End Sub
Aussiebear: When adding sections of code, please use the VBA button to wrap your code. It makes the code so much easier to read.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo Exits
Cancel = True
Application.EnableEvents = False
With ActiveSheet
ActiveWorkbook.SaveCopyAs "C:\TimeSheets\" & Format(Worksheets(3).Range("A12"), " yy-mm-dd") & Worksheets(3).Range("H10") & ".xls"
End With
Exits:
Application.EnableEvents = True
End Sub
Aussiebear: When adding sections of code, please use the VBA button to wrap your code. It makes the code so much easier to read.