I tested it using your code and it works ok, both with excel opened as when excel is not opened (so double click on the filename). See below image for code used. You can try using a DoEvents before the ActiveWorkbook.Close command.