Say for instance the file tries to save over itself and it asks the user "as;lfk already exists, would you like to overwrite the file?" They click "Cancel". Well, when they click cancel it comes up with an error:Code:Private Sub btnSave_Click() Dim ctrlno As String Dim filename As String ctrlno = TextBox1.Text MsgboxResult = MsgBox("Do you already have a referral folder created on your computer?", vbYesNo, "Retail Investment Sales Referral Form") If MsgboxResult = vbYes Then existingfolder = InputBox("Please enter the name of the folder in which your referral files are contained:", "Retail Investment Sales Referral Form") existingfoldercheck = "c:\" & existingfolder If Dir(existingfoldercheck, vbDirectory) <> "" Then filename = existingfoldercheck & "\" & ctrlno & ".xls" ActiveWorkbook.SaveAs filename:= _ filename, FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False End If Else If MsgboxResult = vbNo Then Dim InputBoxResult As String InputBoxResult = InputBox("Please enter a name for the folder to which you will be saving your referrals in:") NewDir = "C:\" & InputBoxResult 'ChDir "C:\" MkDir (NewDir) NewDirMsg = "Your referrals will be saved in:" & NewDir MsgBox NewDirMsg filename = NewDir & "\" & ctrlno & ".xls" ActiveWorkbook.SaveAs filename:= _ filename, FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False End If End If End Sub
Run-time error '1004'
Method 'SaveAs' of object '_Workbook' failed.
How do you keep that from happening?




Reply With Quote