none
C# - Run OneNote 2016 - Addin Macro RRS feed

  • Question


  • Hi friends,

     

    I am trying to run a function from a OneNote COM Addin.

     

    From my C# program?

    I will add it inside a button for now as - im still learning the ropes

       private void Button1_Click(object sender, RibbonControlEventArgs e)
            {
                Application Run  Test.Addin   "NewPage"
            }

     

    Is there some sample code that can show me how?

     

    I have seen that the  OneNote Customisations files exported from OneNote RIBBON  xml shows this:

     

    <mso:customUI xmlns:x2="Test.Addin"

     

    <mso:control idQ="x2:NewPage" visible="true"/>

    The test addin has  a macro function called  "NewPage"   that i want to run from my C# button.

     

    In Excel you can simply do this as an example  -   file name ! macro name

     

     (PERSONAL.XLSB!Hide_All_Worksheets)

     

    But OneNote doesnt have that  :(

     

    I know the macro id name i want to run but how do i access a onenote addin macro from my C#

     

     

    How can i do this?


    Cheers Dan :)




    • Edited by Dan_CS Wednesday, July 26, 2017 10:09 PM
    Monday, July 24, 2017 11:24 PM

All replies

  • Hello Dan,

    In VSTO add-ins, to call its method from other solution, the method should be COM visible and RequestComAddInAutomationService method should be overridden. You could visit Calling Code in VSTO Add-ins from Other Office Solutions According to my test result, I think the method in COM add-in should also be COM visible.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, July 26, 2017 8:46 AM
    Moderator
  •  

    Hello Celeste,

     

    Thank you for advising me.

     

    I read that page

     

    Is it something like below i need to do?

     

    object addInName = "ExcelImportData";

    Office.COMAddIn addIn = Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName);

    ExcelImportData.IAddInUtilities utilities = (ExcelImportData.IAddInUtilities)addIn.Object;

    utilities.ImportData();



     

    Would that make the com visible?

    I want to run a macro in that addin called "NewPage"


    Cheers Dan :)

    Wednesday, July 26, 2017 10:06 PM
  • Hi Dan_CS,

    AFAIK, the Onenote is not the VBA host, it doesn't support the Macros. If you were developing the macros with third-party add-in. You need to contact the support of that com-addin to check whether it supports called by other com add-in. If the add-in were developed by you, you can follow the document mentioned by Celeste.

    In-addition based on the description, it seems that you want to create a page. You can also use the OneNote object model to create a page in the com add-in as a workaround. More detail about creating the page, please refer the CreateNewPage function.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 27, 2017 7:38 AM
    Moderator


  • Hello Fei,

    Ok I understand, so I have to have the addin as com visible.

     

    So for OneNote I need to make it com visible to?

     

    In that case please can you help me with a oneNote inbuilt control id

     

    How do i run this control id from my c# button

     

    The policy id is  : 11739

     

    ClearFormatting

    button

    TabHome

     

    I want to learn how i can access these inbuilt controls from my C# button

     

    private void Button1_Click(object sender, RibbonControlEventArgs e)

    {

    Application.Run OneNote."ClearFormatting"

    }



       

    How do i do the above example

     

    Thank you for your help


    Cheers Dan :)


    • Edited by Dan_CS Friday, July 28, 2017 2:01 PM
    Friday, July 28, 2017 2:00 PM
  • Hi Dan,

     

    >Ok I understand, so I have to have the addin as com visible.

    >So for OneNote I need to make it com visible to?

    To make the function call by from .Net assembly, you need to make the target dll com-visible.

    And the object model of OneNote is different with other Office product(refer here). There is no such object model it exposed to for this scenario.

    As a workaround, you may calling this function by simulate pressing the keyboard. For example, the shortcut for the Clear All Formatting is Ctrl+Shift+N for OneNote 2016. 

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, August 1, 2017 9:56 AM
    Moderator