none
VSTO custom ribbon button won't work outside of Visual Studio RRS feed

  • Question

  • I've constructed a VSTO PowerPoint addin that adds a custom button to the PowerPoint ribbon.  When the button is clicked, it triggers a file open dialog that enables the user to open an Excel spreadsheet.  (This is so my addin can read data from the spreadsheet, manipulate it, and paste into PowerPoint.) 

    Everything works great when I run the addin from inside Visual Studio using "Start Debugging."  But when I publish and try to run it outside Visual Studio (from within PowerPoint), I can see the button I've added to the PowerPoint ribbon, but, when I click the button, nothing happens.  I get no error message.  I extensively researched OneClick and MSI methods of deploying the addin.  I have tried both, but get the same results.  There has to be something I'm missing.  Can anyone help?

    I'm using Office 2013, Visual Studio 2015, and Windows 7.  (I actually get the same results on a machine with Windows 10 and Office 2016.)

    Thanks so much for taking the time to read this.


    • Edited by MattP34 Thursday, March 9, 2017 7:41 PM
    Thursday, March 9, 2017 7:41 PM

All replies

  • Hello Matt,

    > When the button is clicked, it triggers a file open dialog that enables the user to open an Excel spreadsheet. 

    Most probably the file open dialog is displayed behind the main window. Note, you need to specify the parent window handle for the child window or bring it to the foreground programmatically. Is that the case?

    Have you tried creating a log file which can tell you what happens in the code when you click a ribbon button?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, March 9, 2017 8:23 PM
  • Hi MattP34,

    I agree with Eugene  Astafiev that open dialog box is displayed behind the main window.

    to test the button is working or not.

    you can also try to do something like when you click on button it show a messagebox or write some text to slide (just for testing purpose). so that can know that button is working or not.

    if button is working then you can set it's parent window as suggested by Eugene  Astafiev.

    if that also not worked then try to post your code or your addin link. we will try to test it on our side.

    Regards

    Deepak


    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.

    Friday, March 10, 2017 2:31 AM
    Moderator
  • Thanks Eugene and Deepak.  I am currently working on learning how to set that the parent window.  If looks like I need to somehow pass the PowerPoint main window as a parameter in the ShowDialog method of OpenFileDialog.  I'm running into type conversion issues with this parameter but am researching how to work around them.

    I did take Eugene's advice of setting up a log file, but am seeing no results.  So I'll bet you are both correct about the cause of my issue. 

    Friday, March 10, 2017 4:02 PM
  • Hi Matt,

    If it is a buried dialog problem, which I have experienced often with PowerPoint, you might consider just minimizing all windows before your attempt at getting Excel data. I put the following in my PPT add-ins that go after Word document data.

                Dim shell As New Shell32.Shell
                shell.MinimizeAll()
    

    You also need to add a reference to Shell32.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, March 10, 2017 9:00 PM
  • Thanks Rich and everyone. I used the following code to attempt to solve the buried window issue.  What is really strange is that nothing works unless I do a cut/paste of all the slides.  If I select all slides, cut them, and paste them back in, everything works fine.  If I don't do that, still nothing happens when I click my custom ribbon button.  I'm definitely stumped by this behavior.  Editing the PowerPoint in any other way has no effect.  It has to be a cut/paste of all slides.  Does anyone have an idea of what could be causing this?

       NativeWindow pptMain = new NativeWindow();
                pptMain.AssignHandle(new IntPtr(PptPresentation.pptApp.ActiveWindow.HWND));
    
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
    
                openFileDialog1.InitialDirectory = "c:\\";
                openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.RestoreDirectory = true;
    
                if (openFileDialog1.ShowDialog(pptMain) == DialogResult.OK) .....

    Friday, March 10, 2017 9:39 PM
  • Hi MattP34,

    from your last rely I can see that you manage the issue for the window of Open file dialog.

    but you had mentioned that if you cut  and paste all the slides then your code is working.

    I don't know how you try to fetch the data from Excel to powerpoint.

    so here I am confused that it is the issue with the window or with the code to copy data from Excel to powerpoint.

    I suggest you to post your sample code here, that can reproduce the issue.

    we can try to test that code and try to provide you a suggestion to correct it.

    I think that the issue is with your code that is not working if you do not cut paste the slides.

    Regards

    Deepak


    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.

    Monday, March 13, 2017 5:37 AM
    Moderator