Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Loop through a notebook

  • To: mathgroup at
  • Subject: [mg31718] Re: [mg31662] Loop through a notebook
  • From: Omega Consulting <omega_consulting at>
  • Date: Wed, 28 Nov 2001 01:29:43 -0500 (EST)
  • Sender: owner-wri-mathgroup at

At 04:46 AM 11/23/2001, Adam BOUCHTA wrote:
>How does one loop through a notebook which contains sections, subsections,
>A for or do-loop do not work...

It depends on why you want to loop through the notebook.

Often, what you really want is some way to act on different parts of a 
notebook. This can be done by getting the notebook, modifying it and 
putting it back out. This is often easier to program and faster than a 
loop. For example, to remove all output from a nb

cont = NotebookGet[nb];
cont = DeleteCases[cont, Cell[_, "Output"|"Print"|"Graphics", ___], Infinity];
NotebookPut[cont, nb]

If you really want or need a loop, then it's just a matter of SelectionMove.

SelectionMove[nb, Before, Notebook, AutoScroll->False];
SelectionMove[nb, Next, Cell, AutoScroll->False];
cont = NotebookRead[nb];
   SelectionMove[nb, Next, Cell, AutoScroll->False];
   cont = NotebookRead[nb];
   If[MatchQ[cont, Cell[_, "Output"|"Print"|"Graphics", ___]],

Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.

  • Prev by Date: Re: bisection method
  • Next by Date: Re: Aligning subplots nicely?
  • Previous by thread: RE: Loop through a notebook
  • Next by thread: Erbium Doped Optical Amplifier