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

I would like to use "Evaluate Initialization Cells" to open a CellGroup in a notebook. However, the following code doesn't work if placed in an initialization cell:

SelectionMove[SelectedNotebook[], Previous, CellGroup];

When I manually press shift-enter (on the closed CellGroup), then it works as expected by opening the CellGroup. Unfortunately, if I place this code in an initialization cell (in the appropriate location before or after the CellGroup I wish to have opened), the CellGroup doesn't open.

Alternatively, is there an option I can set for CellGroups as there is for a single cell such as using SetOptions with CellOpen -> True?

share|improve this question
up vote 4 down vote accepted

This works :

SelectionMove[SelectedNotebook[], All, EvaluationCell];
SelectionMove[SelectedNotebook[], Previous, CellGroup];

The problem was that in SelectionMove[SelectedNotebook[], Previous, CellGroup], Previous refers to the current selection which is not well defined when you do the initialization.

I have added the line SelectionMove[SelectedNotebook[], All, EvaluationCell]at the beginning so that the selection is the present cell during initialization.

share|improve this answer
Thank you Andre; that works very nicely indeed. – zentient May 15 '13 at 19:16

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.