12
$\begingroup$

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.

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

2 Answers 2

9
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ Why not to simply use the FrontEndExecute[FrontEndToken[InputNotebook[], "EvaluateNotebook"]]? Anyway, good solution! $\endgroup$
    – m0nhawk
    Commented Sep 1, 2013 at 5:40
8
$\begingroup$

There is a Evaluation -> Evaluate Notebook menu for that.

Or, you can set some cells to have Initialization property (documentation on usage).

$\endgroup$
2
  • $\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
    Commented Jun 3, 2019 at 14:40
  • $\begingroup$ "Evaluate Notebook" is now called "Evaluate All Cells" $\endgroup$
    – dronik
    Commented Feb 14, 2021 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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