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.

  • 6
    $\begingroup$ If you're using Windows, why not CTRL+A and then SHIFT+ENTER ? $\endgroup$
    – Rod
    Aug 31 '13 at 23:04

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.

enter image description here

  • 1
    $\begingroup$ Why not to simply use the FrontEndExecute[FrontEndToken[InputNotebook[], "EvaluateNotebook"]]? Anyway, good solution! $\endgroup$
    – m0nhawk
    Sep 1 '13 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$
    – Kutsubato
    Jun 3 '19 at 14:40
  • $\begingroup$ "Evaluate Notebook" is now called "Evaluate All Cells" $\endgroup$
    – zawuza
    Feb 14 '21 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.