# Use Initialization Cells to open a CellGroup

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];
FrontEndTokenExecute["SelectionOpenAllGroups"]


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?

-

This works :

SelectionMove[SelectedNotebook[], All, EvaluationCell];
SelectionMove[SelectedNotebook[], Previous, CellGroup];
FrontEndTokenExecute["SelectionOpenAllGroups"]


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.

-
Thank you Andre; that works very nicely indeed. –  zentient May 15 '13 at 19:16