# How to expand multiple cells at once?

Is there a simple way to expand multiple cells simultaneously?

At the moment I am primarily interested in fully expanding "in one fell swoop" all the cells in a documentation window, although I can imagine situations in which I'd want to open several cells only one-level deep, so I'm interested in this case as well. Finally, it would also be useful to know how to collapse multiple cells at once.

EDIT: My immediate interest is for ways to do this interactively, rather than programmatically. I.e. keyboard (+ mouse) shortcuts, or (second best), menu commands.

EDIT (15-06-25): I ultimately dealt with the closed cells in the documentation pages by modifying the relevant stylesheet so that these cells are opened automatically whenever I visit one of those pages. The solution is a combination of bill s's answer with this other one, more specifically, the recipe labeled Update 2015, stylesheet approach.

The whole solution boils down simply to inserting the following snippet in the appropriate stylesheet file:

CellDynamicExpression:>Refresh[FrontEndExecute[{
FrontEndToken[
EvaluationNotebook[], "SelectAll"]}]; FrontEndExecute[{
FrontEndToken[
EvaluationNotebook[], "SelectionOpenAllGroups"]}], None],


...but, since it took me quite a while to figure out how to carry out the recipe given in the cited answer, I thought that I would spell out the missing details here.

1. create (or locate) the file Reference.nb, as described, and visit it.

2. use Edit > Find... (Ctrl+F) to locate a cell with contents

Local definitions for style "NotesSection":
NotesSection

1. click on this cell's bracket to select it;

2. press Shift+Ctrl+E (alternatively, select Cell > Show Expression); this reveals an Mathematica expression beginning with Cell[...;

3. paste the snippet given above at the appropriate location in the Cell[... expression, as shown in the cited answer's figure;

4. I repeat steps (3) and (4) above (so that the Cell[... is no longer visible);

5. I save the notebook (Ctrl+S).

Do not skip step 6; the changes did not take effect until I got out of the Show Expression state, even after saving the notebook.

-

There are a range of commands that allow you to programmatically control the front end. For example

FrontEndExecute[{FrontEndToken[InputNotebook[], "SelectAll"]}];
FrontEndExecute[{FrontEndToken[InputNotebook[], "SelectionOpenAllGroups"]}];


selects all the cells and opens them.

NotebookFind[InputNotebook[], "Output", All, CellStyle];
FrontEndExecute[FrontEndToken[InputNotebook[], "SelectionCloseUnselectedCells"]];


May also be of use. The places to look for help about these kind of commands is FrontEndToken and the tutorial or this help page.

-
Bill, you missed a couple o'spaces :) – Sektor Sep 20 '13 at 16:04
Thanks! I was actually looking for interactive commands (though I did not make that very clear in my original post). Your answer, however, gave me enough to search with. I found what I was looking for (namely, Ctrl + {) under Cell > Grouping. – kjo Sep 20 '13 at 19:34