2

How can the private stylesheet of the current notebook be exported to some other notebook?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Adalbert Hanßen
  • 2,808
  • 12
  • 26

1 Answers1

1

Do it like this:

ExportStylesheet::usage =
  "ExportStylesheet[fn]\nExports the private stylesheet of the current notebook to some other one designated by fn. If the notebook designated by fn was open before, one would loose unstored edits. To prevent this, the target notebook is saved automatically before closing it.";
ExportStylesheet[fn_] :=
Module[{nbk}
      ,nbk = NotebookOpen[fn];
       If[nbk == $Failed
         ,Print["ImportStylesheet: Wrong Filename: ", fn]; 
          Throw["Wrong filename!"]  (* ===THROW===> *)
         ];
       SetOptions[nbk
                 ,Options[EvaluationNotebook[]
                 ,StyleDefinitions]
                 ];
       NotebookSave[nbk];  (* safeguard against edit losses *)
       NotebookClose[nbk]; (* closes without asking to store *)
      ];                   (* ExportStylesheet *)
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Adalbert Hanßen
  • 2,808
  • 12
  • 26