In MMA 9 I use the following code to load multiple nb's and close them after they are evaluated. In MMA 10 this code is broken. It appears that MMA 10 takes far longer to evaluate the code than the function takes to run, and the NotebookClose closes them before they are completely evaluated in 10. Eliminating the NotebookClose lets the code load properly, but then the user has all of these nb's to close before using the GUI. The point of this code was to have only the nb with the GUI open for the user.
nbs = {"ImportFunctions.nb", "StandardData.nb","DataConditioning.nb", "Functions_1.nb", "Functions_2.nb", "Functions_3.nb", "PaperDifference.nb", "PlotFunctions.nb"};
For[i = 1, i <= Length[nbs], i++,
Block[{nb = NotebookOpen[NotebookDirectory[] <> nbs[[i]]]},
FrontEndTokenExecute[nb, "EvaluateNotebook"];
NotebookClose[nb];
]
]
Is there a better way to accomplish this in MMA 10?
A modification of procedure1[] from the answer by Kuba that does something recognizable when evaluated in version 9, but not in version 10.4.1:
procedure0[] := Module[{nbs},
nbs = Table[With[{i = i},
NotebookPut @ Notebook[{Cell[BoxData@MakeBoxes[Speak[ToString@i]], "Input"]}]], {i, 4}];
For[i = 1, i <= Length[nbs], i++,
FrontEndTokenExecute[nbs[[i]], "EvaluateNotebook"];
NotebookClose[nbs[[i]]];];
Print["is this really finished?"];]
procedure0[]
A simpler single notebook example
With[{nb = NotebookPut @ Notebook[{Cell[BoxData@MakeBoxes[Speak["Hi"]], "Input"]}]},
FrontEndTokenExecute[nb, "EvaluateNotebook"]; NotebookClose[nb];]
procedure1, that works in version 9, but not in version 10.4.1, to the question. – Karsten7 Jul 27 '16 at 17:52NotebookClose[]to the end of the individual notebooks together with removingNotebookClose[nb]from the given code work? – Karsten7 Jul 27 '16 at 18:40