Link to home
Start Free TrialLog in
Avatar of coperations07
coperations07Flag for United States of America

asked on

Close external application

Hi,
Using VB2005.
I have code in a click event that opens a slide show. I want to also have code that will close the slide show(close powerpoint all the way).
I've tried the attached code. The first code gives the following error at pptApp.ActivePresentation.Close():
"Unable to cast COM object of type 'PowerPoint.ApplicationClass' to interface type 'PowerPoint._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{91493442-5A91-11CF-8700-00AA0060263B}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."

The second code gives this error at proc.Kill():
"no process is associated with this object"

What's the best way to close an application?

Thx,
Dave
'Dim pptApp As PowerPoint.Application
        'pptApp = New PowerPoint.Application
 
        'pptApp.ActivePresentation.Close()
 
 
        Dim proc As New Process
        proc.StartInfo.FileName = "C:\Program Files\American Greetings\SlideShow\Sorter_Show.ppt"
        proc.Kill()

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Can you try something like the following (this assumes you are using a reference to Microsoft PowerPoint 11.0 Object Library):
Dim pp As New Microsoft.Office.Interop.PowerPoint.Application
 
pp.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue
pp.Presentations.Open("C:\test.ppt")
 
Console.ReadKey() ' Simulates code in between your open and close statement
 
pp.Quit()

Open in new window

Avatar of coperations07

ASKER

I tried your code, but it says I need a reference. I don't see the reference it's asking for. I attached a screen shot of the message.

Microsoft.Office.Interop.PowerPoint is the only powerpoint ref. I see. Where would I get the 11.0?
vb.doc
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The link brings up the Add Reference box for me to select a reference, but I don't see the reference that I need. It's the same as going to project/add reference....
The reference to Microsoft PowerPoint...  is on the COM tab. If you can't find it there, which version of VS are you using?
untitled.JPG
Microsoft Powerpoint 9.0 Object Library is there, but not 11.0.

I'm using Microsoft Visual Studio 2005.
I'm using VS 2008, so that's probably the reason for the discrepancy. 9.0 should be fine and the syntax should be the same.
I've already added the 9.0 reference and I still get the same error as above..
The only thing I can think to do now would be to try installing the following update/package:

http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en

It *should* install the updated libraries. I tried creating a 2005 project on my home computer and I have the libraries already--but that may be because I have Office 2003 installed. Try the link above and see if you get the necessary libraries.
I downloaded the update, but I still get the same error. I put the downloaded files into "C:\Program Files\Microsoft Office\Office". Not sure if that's where they need to be.

My version of powerpoint is 2000. I noticed this download was for 2003. I have outlook 2003, but PP,Word,Excel, and Access are the 2000 version.
I found the reference I needed. It did tell what it was in the error message. I just didn't know where to find it.

So now the only code w/ a blue line is: Microsoft.Office.Core.MsoTriState.msoCTrue

It says that MsoTriState is ambiguous in the namespace Microsoft.Office.Core

What can I do about this?
This means you have two libraries that both define something called Microsoft.Office.Core.MsoTriState. You can try to decipher which library is causing the conflict. That particular variable (visible) seems to be an enumeration to me (which tells me it is some form of numeric value). You could try setting it to 1 or a higher integer value to see if you get the desired result.
I set pp.Visible = 1 and it gives this error...
Unable to cast COM object of type 'Microsoft.Office.Interop.PowerPoint.ApplicationClass' to interface type 'Microsoft.Office.Interop.PowerPoint._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{91493442-5A91-11CF-8700-00AA0060263B}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

How do I go about deciphering the conflicting libraries? I don't see a way to remove the references once they are referenced. Is there a way to do this?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial