({{, (RefLink[ButtonNotebook, paclet:ref/ButtonNotebook])[]
gives the notebook, if any, that contains the button which initiated the current evaluation. }})

OpenersNotesSection(Spacer1)Details

(RefLink[ButtonNotebook, paclet:ref/ButtonNotebook]) returns a (RefLink[NotebookObject, paclet:ref/NotebookObject]).

If a button in a palette initiates evaluation in another notebook, then (RefLink[ButtonNotebook, paclet:ref/ButtonNotebook])[] will be the palette, but (RefLink[EvaluationNotebook, paclet:ref/EvaluationNotebook])[] will be the other notebook.

If the current evaluation was not initiated by a button, then (RefLink[ButtonNotebook, paclet:ref/ButtonNotebook])[] will return (RefLink[$Failed, paclet:ref/$Failed]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Make a button that sets nb to the (RefLink[NotebookObject, paclet:ref/NotebookObject]) for the button's notebook:

Button["Set nb",nb=ButtonNotebook[]]

After the button is clicked, the variable is assigned:

nb

Use the object for further processing:

Options[nb,WindowSize]

OpenersExampleSection1(Spacer1)Applications  (1)

Create a palette button that writes to the input notebook and then closes the palette:

pal=CreatePalette[{Button["Test",NotebookWrite[InputNotebook[],"Done"];NotebookClose[ ButtonNotebook[]]]}];

OpenersExampleSection2(Spacer1)Properties & Relations  (1)

The button notebook is sometimes not the same as the current input notebook:

Button["New notebook",CreateDocument[];bnb=ButtonNotebook[]; inb=InputNotebook[]]

After clicking the button, these two notebooks are different:

"WindowTitle"/.(NotebookInformation/@{bnb,inb})

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Notebooks, paclet:ref/Notebooks])  ▪  (RefLink[EvaluationNotebook, paclet:ref/EvaluationNotebook])  ▪  (RefLink[SelectedNotebook, paclet:ref/SelectedNotebook])  ▪  (RefLink[InputNotebook, paclet:ref/InputNotebook])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Manipulating Notebooks from the Kernel, paclet:tutorial/ManipulatingNotebooksFromTheKernel])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Low-Level Notebook Programming, paclet:guide/LowLevelNotebookProgramming])}})}})