Closes document before deleting it to prevent it from reappearing