M
michael.beckinsale
Hi All,
The situation is this:
I have a workbook being used as psuedo template. When it is opened the
1st thing the user has to do is enter a date via a calendar picker. The
week no forms part of the default file name which is contained in say
cell A1 ie myfileWK30.
For control purposes if the file is saved using either, Save, Save As
or by using the Save icon it must be saved using the filename in cell
A1 ie myfileWK30
My code to try to do this is pasted below and l am failing woefully.
Additionally the SaveAs dialog is showing when it is not suppossed to!
All help very gratefully appreciated
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim DFN
Application.EnableEvents = False
DFN = Sheets("Sheet1").Range("A1").Value & ".xls"
If ThisWorkbook.Name <> DFN Then
DFN = Sheets("Sheet1").Range("A1").Value
ThisWorkbook.SaveAs DFN
Else
ThisWorkbook.Save
End If
Cancel = True
Application.EnableEvents = True
End Sub
Regards
Michael Beckinsale
The situation is this:
I have a workbook being used as psuedo template. When it is opened the
1st thing the user has to do is enter a date via a calendar picker. The
week no forms part of the default file name which is contained in say
cell A1 ie myfileWK30.
For control purposes if the file is saved using either, Save, Save As
or by using the Save icon it must be saved using the filename in cell
A1 ie myfileWK30
My code to try to do this is pasted below and l am failing woefully.
Additionally the SaveAs dialog is showing when it is not suppossed to!
All help very gratefully appreciated
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim DFN
Application.EnableEvents = False
DFN = Sheets("Sheet1").Range("A1").Value & ".xls"
If ThisWorkbook.Name <> DFN Then
DFN = Sheets("Sheet1").Range("A1").Value
ThisWorkbook.SaveAs DFN
Else
ThisWorkbook.Save
End If
Cancel = True
Application.EnableEvents = True
End Sub
Regards
Michael Beckinsale