Help required: Disable SaveAs

MI man

Registered User.
Local time
Today, 05:03
Joined
Nov 23, 2008
Messages
59
Hi Everyone,

I am currently using Excel 2003 version.

I am developing an application which does not gets closed if all the required fields are not filled up in a particular spreadsheet. And, if all the fields are filled up, then upon clicking upon the button 'SAVE' (which I have developed using commandbutton), the SAVEAS dialog box opens up and asks for the file to save with a name.....
However, the SAVEAS dialog box has SAVE and CANCEL options (at the extreme right hand side)....Upon clicking on SAVE, the file gets saved to a desired location, but when clicked upon CANCEL (which is clicked when intended to cancel the saving), the file still gets saved with the name 'FALSE' in My Documents folder and the application is getting closed.

Could anyone please help in avoiding this CANCEL situation wherein if CANCEL is selected, only the dialog box gets cancelled and the application remains as it is without getting closed....??
 
Well, it would help if you posted the code you are currently using. Just remember, the majority of us here can't read minds nor see your application from where we sit/stand/lay.
 
Well, here is the code:

Private sub CommandButton1_Click()
Dim fname as String

If cells(4,4)="" or isnull(cells(4,4)) or isempty(cells(4,4)) then
Msgbox "Input Highlighted field", vbCritical, "Missing Field"
Cells(4,4).select
Exit Sub

Elseif cells(5,4)="" or isnull(cells(5,4)) or isempty(cells(5,4)) then
Msgbox "Input Highlighted field", vbCritical, "Missing Field"
Cells(5,4).select
Exit Sub

Else
rtn=Msgbox ("Click on YES to SAVE the file, Click on NO to Cancel",
vbExclamation+vbYesNo, "Save File")

If rtn=vbYes then
fname=Application.GetSaveAsFilename
Activeworkbook.SaveAs Filename:=fname
Activeworkbook.Close
Elseif rtn=vbNo then
Exit Sub
End if

End if

End Sub
 
It would be this:
Code:
rtn=Msgbox ("Click on YES to SAVE the file, Click on NO to Cancel", 
vbExclamation+vbYesNo, "Save File")
 
If rtn=vbYes then
   fname=Application.GetSaveAsFilename
 
   If fname <> "False" Then
      Activeworkbook.SaveAs Filename:=fname
   End If
 
   Activeworkbook.Close
 
Else
   Exit Sub
End if
You don't need ElseIf rtn=vbNo because if they haven't pressed yes, then they had to have pressed no. So all you need is the else.
 

Users who are viewing this thread

Back
Top Bottom