Thanks for your help.
Actually the problem was that the macro was triggered by an open file event.
If I run it manually it works.
Is this the way it is suppose to work. That if it triggered by an open file event it can not open a file in the current tab which would then close the original file?
It all depends on how EmEditor opens the file, and how you open the file with your macro. How EmEditor opens the file depends on your settings (Configuration Properties > File tab in Changed by Another Program drop-down list box). Also, if you open a large file, EmEditor might open in asynchronous mode (you can set the threshold in the Customize > Advanced tab). I hope this information helps.