I have not used this code in quite a while but I think it still works. The calling notebook could be
Dynamic[{loop, linked`vdtdz}]
distab = {}; Dynamic[distab // TableForm]
Dynamic[return]
Do[linked`vdtdz = 0.1 loop; linked`$callingNotebook = EvaluationNotebook[];
return = NotebookEvaluate[$UserDocumentsDirectory<>"/Mathematica/PSTD_Solve.nb"];
distab = Append[distab, linked`maxai], {loop, 8, 10}]
It passes a variable
linked`vdtdz
and saves the returned variable
linked`maxai
It also temporarily displays a pair of plots produced by the called notebook.
The called notebook begins with
linked = ValueQ[linked`$callingNotebook]; Clear[linked`$callingNotebook]
which determines whether the called notebook actually has been called by another notebook, as opposed to being run on its own. Later, the called notebook uses the passed variable
vdtdz = If[linked, linked`vdtdz, 1.0]; \[CapitalDelta]t0 = vdtdz \[CapitalDelta]z0/vz0
Still later, the called notebook saves plots to disk, depending on whether it actually has been called by another notebook.
If[linked, saveplot = True, (*other code*)]
On its last line of code, the called notebook stores the answer to be returned to the calling notebook and also creates a final pair of plots which automatically are returned.
If[linked, linked`maxai = kout[[1, 4]]; Grid[{{grow3D, growContour}}]]
This may be more than you want. If so, delete what is unnecessary (the plots and the use of Dynamic, for instance).
contextthat is shared between the two notebooks in order to share variables between them. After the called notebook returns, store the answer. – bbgodfrey Feb 05 '20 at 17:46