I have created a notebook, with functions. The only thing that I want to change in the notebook later is the input file. I therefor want to have a button that runs every input step-by-step so that I do not have to go into every input and press enter for it to update. How could this be done.
2 Answers
Perhaps the simplest thing is to command-A and enter, which selects all the cells and evaluates. Or you can use a button
evalStart := Module[{},
FrontEndExecute[FrontEndToken[InputNotebook[], "EvaluateInitialization"]];
FrontEndExecute[FrontEndToken[InputNotebook[], "SelectAll"]];
FrontEndExecute[FrontEndToken[InputNotebook[], "EvaluateCells"]];];
Button["do it", evalStart]
When you evaluate this, a button appears. Every time you press the button, it evaluates everything by first evaluating the initialization cells (if any), then selecting all, then evaluating all the cells.
-
1$\begingroup$ Why not to simply use the
FrontEndExecute[FrontEndToken[InputNotebook[], "EvaluateNotebook"]]
? Anyway, good solution! $\endgroup$– m0nhawkCommented Sep 1, 2013 at 5:40
There is a Evaluation -> Evaluate Notebook
menu for that.
Or, you can set some cells to have Initialization
property (documentation on usage).
-
$\begingroup$ Since he/she asked for a button, the other answer is "better" but you are totally right: There's a simple menu function for that. $\endgroup$ Commented Jun 3, 2019 at 14:40
-
$\begingroup$ "Evaluate Notebook" is now called "Evaluate All Cells" $\endgroup$– dronikCommented Feb 14, 2021 at 20:09