Error trapping
-
I wonder if anyone can help me? I have a small piece of vba in excel that works fine except for one thing. It saves a spreadsheet in as particular directory with a specified name but if it encounters a file of the same name already there and you click no to the save it then dies with error 1004. Can anyone assist? Here is the code: Private Sub CommandButton3_Click() siv = ActiveSheet.Cells(6, 2).Value 'ActiveWorkbook.SaveAs Filename:="C:\My Documents\" & siv & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False On Error Resume Next ActiveWorkbook.Close End Sub X|
-
I wonder if anyone can help me? I have a small piece of vba in excel that works fine except for one thing. It saves a spreadsheet in as particular directory with a specified name but if it encounters a file of the same name already there and you click no to the save it then dies with error 1004. Can anyone assist? Here is the code: Private Sub CommandButton3_Click() siv = ActiveSheet.Cells(6, 2).Value 'ActiveWorkbook.SaveAs Filename:="C:\My Documents\" & siv & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False On Error Resume Next ActiveWorkbook.Close End Sub X|
-
What on earth is error 1004 is a window error code? 1004 = Invalid flags. as an internal Windows error code try using the default params?
The on error resume should avoid but doesnt. The error is that it is finsindg an existing file of the same name and then falls over when you click no or cancel as oppsed to yes because the function is saveas hence the saveas has failed. SO how to get around the failure of the function????