2008-03-13

Iterating Through Mathematica Notebook Cells

The following snippet will iterate through the all the cells in a Mathematica notebook and close all Input cells:

Module[{nb, cell},
 nb = Notebooks["mynotebook.nb"][[1]];
 SelectionMove[nb, Before, Notebook];
 While[SelectionMove[nb, Next, Cell]; cell=NotebookRead[nb]; {}=!=cell,
  If["Input" == cell[[2]], 
   SetOptions[NotebookSelection[nb], "CellOpen" -> True] ]
  ]
 ]