# Retrieving a list of tagged output cells and a list of variables from various Notebooks into a new Notebook

The table below provides the information needed to formulate my question: how can I gather a selected number of tagged output cells and variables in a new notebook?

I have two notebooks nb1 and nb2. These notebooks have tagged input cells uniquely named such as tc11 and tc21 in nb1; similarly, tc41 and tc53 in nb2. In the 3rd column of the table, I give two sample lists of the output cells that I want to gather in a new Notebook (newNB). For example, {tc11, tc46} and {tc31, tc53, tc46} are the lists that I like to bring into newNB.

In nb1 and nb2, I also have variables to be brought into newNB. Examples of variable lists include {var11, var22} and {var21, var12}.

I like to have a Mathematica function such as:

gatherF[lstNB_, lstOUT_, lstVAR_]:=


with three arguments: list of notebooks (lstNB), list of tagged output cells (lstOUT), and list of variables (lstVAR).

Note that tagged output cells inherit tagged input cells, meaning that input and output cells have the same name. I only want the tagged output cells, not input cells.

• What do you mean by "variables to be brought into newNB"?
– Kuba
Dec 11, 2019 at 9:11
• @Kuba: A variable is a calculation done in a notebook, such as x=y+3 where I call x as a variable. In my real case, a tagged cell includes a Manipulate[...] and I want to get the output from the Manipulate. Whereas a variable is defined out of the Manipulate. Dec 11, 2019 at 12:12
• @Kuba: My explanation of a variable is not complete. I do not want to get the value assigned to x but I want x variable to be active in the new notebook so that I can use it in other calculations. Dec 11, 2019 at 12:26

Let me know if it fits your needs:

notebooks = {(*__NotebookObject*)};
tags = {(*__String*)};
styles = {"Output"};

notebooks //
Map[Cells[#, CellStyle -> styles, CellTags -> tags] &] //
Flatten //

• I run your code with an example. There is no error nor warnings. The only output I get is a NotebookObject[...]. Does this NotebookObject include the outputs I am after? If so, how can I open this NotebookObject? Thank you very much for the code. Dec 11, 2019 at 12:21
• @TugrulTemel That is weird, does this create a window for you: CreateDocument[]?
• Yes, it creates a window including only Print[...], which is something I like to print. But this window is just showing that CreateDocument[...]` has worked, however, I do not see any printout result. Dec 13, 2019 at 22:02