MATLAB: Cancel the beep and an error msg in GUI button cancellation

gui buttonxlswrite

I created a save2XLS button in GUI that contain the following code:
[filename,pathname]= uiputfile('*.xls','Save as');
column=get(handles.foTable,'columnname')' ;
dataX=get(handles.foTable,'data');
num=[column;dataX];
fullFileName = [pathname filename]
if exist(fullFileName)
%overwrite the file
delete([pathname filename])
xlswrite([pathname filename],num);
else
%write new file
xlswrite([pathname filename],num);
end
If I decide to cancel the "save as" operation by clicking the X or the cancel button I get a beep and an error in the command window. How can I cancel it?
Thanks

Best Answer

Bail out if they click cancel
if filename == 0
return;
end