I am new here, so let me know if this question is inappropriate. I've been stuck for many hours on this puzzle. I know it should be easy, but for me...?

I want to create a Notebook (call it "Index of Related"), located in directory "C:\somewhere\strange" (not necessarily in $Path) which contains a list of notebooks I use at the same time, but quite independently of one another. One application might be a list of all the Mathematica notebooks I use in my microeconomics course.

From inside "Index of Related", if I click on a button, I want Mathematica to load some other notebook, just as if I had used File/Open in Mathematica.

I can't seem to create buttons to execute simple File/Opens! Every coding I've tried adding to Index of Related" seems to load the other notebooks into or inside Index of Related or generate $Failed.

Example X: Example of an application:

  • File 1, located in C:\directory1 : Slide show for the talk....

  • File 2, located in c:\dogs\small : My text for the talk....

  • File 3, located somewhere in $Path : Handouts for the talk....
  • File 4: References for the talk....
  • Files 5-8, located all over the place: Examples for the talk, created for other projects, so in various other directories....

Now, while creating the talk I first load "Index of Related". I stumble on a reference, so I open Files 2 and 4 and make changes. In a later session, I want to create from this reference a slide, so I open and work in File 2.


2 Answers 2


The following code

Button["Open File 1",  NotebookOpen["filename"]]

opens an existing notebook (with name and complete path in "filoename") in a new window.

Example that should work on all systems:

base = FileNameJoin[{$InstallationDirectory, "SystemFiles", 
    "FrontEnd", "Palettes"}];
   NotebookOpen[FileNameJoin[{base, "BasicMathAssistant.nb"}]]],
   NotebookOpen[FileNameJoin[{base, "StylesheetChooser.nb"}]]],
   NotebookOpen[FileNameJoin[{base, "WritingAssistant.nb"}]]]

Mathematica graphics
Mathematica graphics

  • $\begingroup$ This works great. Now I hope "we" (meaning you-all!) can make it even more useful. I have very long Notebooks, and I want to Open them to specific text strings. For example, if I will give a lecture on "monopoly" I want a button which will load my microeconomics class lectures notebook and as part of opening it will scroll down to where the text "monopoly behavior" occurs which happens to be roughly on page 145 of that notebook. I have worked several hours trying to find a way. No luck so far. $\endgroup$
    – GeofAndron
    Commented May 11, 2019 at 22:49

If you don't need buttons and don't insist on constructing the index by coding, then you can just use Text cells where you type a name for the notebook, select the name, then use the menu command Insert > Hyperlink to open a dialog. In that dialog, select "Other notebook or URL", then use its Browse button to locate the notebook, etc.

For example, if you type "ChartElementSchemes" in the Text cell and then create the hyperlink to that palette, you'll just see the characteristic coloring indicating a hyperlink. If you examine the cell's contents, you'll see:

 FrontEnd`FileName[{$RootDirectory, "Applications", "Mathematica.app", 
 "SystemFiles", "FrontEnd", "Palettes"}, "ChartElementSchemes.nb", 
 CharacterEncoding -> "UTF-8"], None}]], "Text"]

While this method doesn't allow you to just type code and doesn't create nice buttons to see, it does have the advantage that you can in fact browse to find the notebooks in question. Of course you can fancy up what you see by creating a Table in the text cell and include a frame, say.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.