Batch mode macro doesn't work properly when it loops

run("Auto Local Threshold...", "method=Bernsen radius=15 parameter_1=40 parameter_2=0 white");
run("Watershed");
run("Analyze Particles...", "size=10-Infinity clear summarize add");
roiSelect = newArray();
size = roiManager("count");
for (x=0; x<size ; x++)   	
   	  {
		roiSelect = Array.concat(roiSelect ,x);
  }
roiManager("select", roiSelect);
roiManager("combine");

The above code is part of my macro, and something very strange is happening. If I keep the ROI Manager open, the code runs perfectly fine, but when I close the ROI Manager, I get an error at the indicated line, where it says that “either several ROIs or none must be selected”

Does anyone know what’s going on? I appreciate all the help!

I don’t see that you indicated a line, but I think the ROI manager should be opened during the Analyze Particles step. If you are closing it, then I would not be surprised that the combine step would fail. Why are you closing the ROI manager?

I edited your macro to be code, it will be easier for anyone else that wants to test it.