OneNote examples?

Add-in Express™ Support Service
That's what is more important than anything else

OneNote examples?
I need some help getting started making a OneNote plugin 
Subscribe
Kris Tjærnås




Posts: 2
Joined: 2017-09-15
I could not find any add-in-express examples for making a OneNote plugin. I tried using the generic Office COM example/howto here https://www.add-in-express.com/docs/vcl-first-addin.php, fetching the Window with:
IWindow := HostApp.ActiveWindow;

then I did the:
try
if IWindow <> nil then
case HostType of
ohaOneNote:
(IWindow as OneNote2010.Window).Application.GetHierarchy('',hsNotebooks, notebookXml, Onenote2010.xs2013);

I put an exception on both of these to see where it fails, and it fails already on the first IWindow := HostApp.ActiveWindow; with E.message = "Library not registered".

Am I going at this totally wrong?
Could anyone please help point me in the right direction on how to create a OneNote addin that can manipulate notebook contents?
Posted 15 Sep, 2017 06:31:51 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
Hello Kris,

There's no Application.ActiveWindow property on the OneNote object model. The code below works fine for me.

procedure TAddInModule.adxRibbonTab1Controls0Controls0Click(
  Sender: TObject; const RibbonControl: IRibbonControl);
var
  IWindow: IDispatch;
  notebookXml: WideString;
begin
  IWindow := OneNoteApp.Windows.CurrentWindow;
  if IWindow <> nil then begin
    (IWindow as OneNote2010.Window).Application.GetHierarchy('',hsNotebooks, notebookXml, Onenote2010.xs2013);
    ShowMessage(notebookXml);
  end;
end;


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Sep, 2017 07:43:03 Top
Rakkafant




Posts: 2
Joined: 2017-09-15
Ah, that was it - I needed a different approach to the IDispatch interface. OneNoteApp.Windows.CurrentWindow; :)

Thank you so much Andrei! :)

Best wishes,
Kris
Posted 18 Sep, 2017 12:41:02 Top
Andrei Smolin


Add-in Express team


Posts: 14106
Joined: 2006-05-11
You are welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Sep, 2017 02:22:09 Top