L
Libby
Hi
I have a read-only file and I want to display the SaveAs dialog box and
suggest a filename which is a date on the worksheet, when either Save or
SaveAs is clicked.
I had a problem with the SaveAs dialog box being displayed twice as it was
readonly file but I think I've cured that. The problem now is that the
Workbook is saved with the suggested filename even if the user trys to change
it to something else.
Here is my code
Public SAflag as boolean 'true if BeforeSave run
Private Sub Workbook_Open
SAflag = False
end sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
dim fName
if IsDate(Sheet1.range("b3").value)=true then
fName = format(Datevalue(Sheet1.range("b3").value), "dd-mm-yyyy")
end if
if SAflag = false then
if SaveAsUI = true then
Cancel = True
Application.GetSaveAsFilename(fName)
if fName<>False then
SAflag = True
Thisworkbook.SaveAs(fName)
end if
end if
end if
end if
end sub
Thanks Guys
I have a read-only file and I want to display the SaveAs dialog box and
suggest a filename which is a date on the worksheet, when either Save or
SaveAs is clicked.
I had a problem with the SaveAs dialog box being displayed twice as it was
readonly file but I think I've cured that. The problem now is that the
Workbook is saved with the suggested filename even if the user trys to change
it to something else.
Here is my code
Public SAflag as boolean 'true if BeforeSave run
Private Sub Workbook_Open
SAflag = False
end sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
dim fName
if IsDate(Sheet1.range("b3").value)=true then
fName = format(Datevalue(Sheet1.range("b3").value), "dd-mm-yyyy")
end if
if SAflag = false then
if SaveAsUI = true then
Cancel = True
Application.GetSaveAsFilename(fName)
if fName<>False then
SAflag = True
Thisworkbook.SaveAs(fName)
end if
end if
end if
end if
end sub
Thanks Guys