I've encountered the following issue with NotebookEvaluate (note the grouping into 3 distinct cells):

(* Cell 1 *)
(* "Global`" *)

(* Cell 2 *)
SetOptions[EvaluationCell[], CellContext -> Notebook]
nb3 = NotebookCreate[];
NotebookEvaluate[nb3, InsertResults -> True];
(* "Notebook$$16$795021`" *)

(* Cell 3 *)
(* "Notebook$$16$795021`" *)

As can be seen, the NotebookEvaluate cell breaks the $Context of the original notebook.

Am I missing something? Or is this simply a bug? And most importantly, what's the easiest way to fix this?

I could wrap the whole thing inside Block[{$Context=$Context},...] but that doesn't seem right - It doesn't fix the issue properly, as I cannot wrap the Block directly around the NotebookEvaluate, as the context is already wrong there, it just fixes the symptomes later



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.