GetSaveasFileName

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
 
D

Dave Peterson

Maybe just stopping the .saveas from calling the _beforesave would work:

If fName <> False Then
SAflag = True
Application.EnableEvents = False
ThisWorkbook.SaveAs fName
Application.EnableEvents = True
End If

If it doesn't you may want to paste directly from your code--I think you had a
typo in your post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top