VBProject causes an exception in PowerPoint .NET Add-in

M

Marc Ridey

To bring it down to a simple problem.
As soon as I access the VBProject property of a presentation from a .NET
Office Add-in, later on when I close PowerPoint, I get an Exception.

To reproduce:

Environment: VS.NET 2003, Office 2003, OS either Server2003 or XPPro.

1. Open VS.NET 2003
2. Create a new "C# shared addin for PowerPoint"
3. Add "Microsoft.Office.Interop.Powerpoint" and "Microsoft.Vbe.Interop"
assemblies
4. Add a blank form, Form1
5. Add a button on the form
6. Add an instance of the form in Connect.cs
7. Pass the PowerPoint application hadnle to the form in OnConnection and
show the form.
8. In the button handler, add one line "if (app.ActivePresentation.VBProject
== null) return;

Yes, the line does nothing, it's just a mean to trigger an access to the
property VBProject.

Now, build the project, build the setup, run the setup, run powerpoint.

You should get your non-modal form displayed when powerpoint starts.
With a presentation opened (even a blank one), press the button to trigger
an access to VBProject.

Close the presentation
Close Powerpoint

When I close PowerPoint, a few seconds later, I get an exception.

Marc
 
E

Eugene E. Starostin

By default you cannot get access to VBProject. Look at the "Trust access to
Visual Basic Project" check box on Tools | Macro | Security | Trusted
Sources.


Regards from Belarus
Eugene Starostin
 
M

Marc Ridey

Yes, sorry I should have mentioned that Trust Access to Visual Basic Project
is allowed. I have a large project where I do a lot of access to the VB Code
of PowerPoint presentations.
The code works fine, the presentations are created and modified as expected.
It's just when I close PowerPoint, after closing all the presentations that
Powerpoint throws an exception out of nowhere. I've narrowed it down to just
accessing the VBProject property.
Basically I'm trying to make my add-in user friendly so that PowerPoint
don't crash everytime it's closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top