Dear,
You can use "Submit and return " statement. As in your case, if there is no record is found, it must not go for generating excel sheet. Put the check if no record found dont go for excel generating.
Hope these two steps will resolve your query.