0
$\begingroup$

My objective is to read the results of several tagged cells in a notebook NB1 from another notebook NB2. Following the suggestions of a member of this forum, I have written the following code, which works only for a single tagged cell at a time.

(* I saved the following code at the bottom of NB1 (called "filename.nb"), which includes all  the tagged cells*)
ClearAll[listTags,nb];
listTags = {"Data", "Multiplier", "SectorChains"};
nb = CreateDocument@{
ExpressionCell[Defer[Print["Data"], "Input", CellTags -> {"Data"}],
ExpressionCell[Defer[Print["Multiplier"], "Input", CellTags -> {"Multiplier"}],
ExpressionCell[Defer[Print["SectorChains"], "Input", CellTags -> {"SectorChains"}] };
nb = NotebookOpen["C:\\Desktop\\filename.nb"];

(*I run the following code in `NB2` while keeping `NB1` open*)
Get["C:\\Desktop\\filename.nb"];
NotebookEvaluate[nb, EvaluationElements -> {"Tags"->{"SectorChains"}}]

If I want to read the results of more than one tagged cell in one run, it does not work; and NB1 is automatically closed, generating the message: NotebookEvaluate[] is not able to find NotebookObject[].

My ultimate purpose is to run it for the entire list of tags listTags. Furthermore, I really like to know why NB1 is closed. Is this a bug?

$\endgroup$
  • $\begingroup$ I can't reproduce the errors you are describing - for me, the notebook stays open as expected. Also, what do you want to achieve with the Get[...] command? Isn't that double-evaluating the content of the notebook? As for your problem: Do you want to evaluate the tagged cells one-by-one, reading their results, or do you want to evaluate the whole notebook, and then read the results from cells with the appropriate tags? $\endgroup$ – Lukas Lang Dec 9 '19 at 21:59
  • $\begingroup$ @Lukas Lang: You are right about Get[...]. I want to evaluate the whole notebook and read the results from cells with the appropriate tags. Thanks for your help. $\endgroup$ – Tugrul Temel Dec 9 '19 at 22:26
  • $\begingroup$ Do you want to only read results or do you need the procedure to evaluate appropriate cells, or the whole notebook too? $\endgroup$ – Kuba Dec 13 '19 at 7:58
  • $\begingroup$ @Kuba: I can already read the results in a new notebook by Get["file path"] and then just type the name of the tagged cell or variable name. No problem with this procedure, however, to do that, I need to keep all the relevant files open and run them. This is a bit unnecessary for my purpose. I do not want to open the files and get the results in a new notebook. I needed a programming procedure to do all these hectic work for me: run necessary noteboks without opening them and import the results of interest to a new notebook. $\endgroup$ – Tugrul Temel Dec 13 '19 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.