I have a long nb file. I want to subdivide different sections into separate smaller nb files and call and run them in a common nb file. How do I achieve this?
I tried Import["path/filename.nb"] but it did not work. Any ideas?
you can mark your cells as initilization cells (right click on the brackets -> initialization cell) and save it as a package (.m file). You can automatically save it as a package file by going into "Format -> Option Inspector", select "Selected Notebook" in "Show option values" goto "Notebook Options -> File Options" and set "AutoGeneratePackage" to "Automatic".
Thank you Marcel. Yes, I have been doing that. But you see, the .m files are written in the standardform (I mean the way we write it in fortran). To me, the greatest advantage of .nb file is that we can write the expressions as printed in the book. So it is very easy to detect a mistake in .nb file. So I was wondering whether smaller .nb files can be called inside another .nb using Get.
If you want to keep it as a *.nb file then try using the following in your main notebook,
nb1 = NotebookOpen[filename];
SelectionMove[nb1, All, Notebook]
SelectionEvaluate[nb1]
This will open the notebook "filename", select all the elements of the notebook and then run them.
You could also include an extra line,
NotebookClose[nb1]
at the very end of the notebook "filename.nb" so that it closes itself once it has finished running. Then you have all the expressions in your kernel and you can continue to do some calculations.