Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's assume I want a button that, when you click it, get the cell that contains it selected. This approach won't work, it selects the cell containg the selection previous to the click.

Button["Select this cell", SelectionMove[ButtonNotebook[], All, Cell]]
share|improve this question
up vote 11 down vote accepted


Button["Select this cell", SelectionMove[ButtonNotebook[], All, EvaluationCell]]
share|improve this answer
This is better than mine. +1 – halirutan Mar 15 '12 at 2:59
@halirutan I just browsed the help ... beginner's luck :) – Dr. belisarius Mar 15 '12 at 3:04

What you could use is NotebookFind to search inside your notebook for something unique which distinguishes your Button from all other.

Here I looked at the cell-structure of your Button and used it to make a small function which creates exactly this button-cell with the exception, that it adds a CellTag. The Button itself just searches for this CellTag and selects the Cell where it is found. As a unique string I used simply the creation-time of the button:

MakeSelectionButton[] := With[{t = DateString[]},
      ButtonBox["\<\"Select this cell\"\>",
        Appearance -> Automatic,
        ButtonFunction :> NotebookFind[
            ButtonNotebook[], t, All, CellTags],
        Evaluator -> Automatic,
        Method -> "Preemptive"]], "Output", CellTags -> t]

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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