• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1934
  • Last Modified:

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

0
coperations07
Asked:
coperations07
  • 8
  • 6
2 Solutions
 
käµfm³d 👽Commented:
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

0
 
coperations07Author Commented:
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
0
 
käµfm³d 👽Commented:
If you take a look at your error message, VS offers to add the reference for you. Try clicking the link to resolve the reference. See attached.
untitled.JPG
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
coperations07Author Commented:
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....
0
 
käµfm³d 👽Commented:
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
0
 
coperations07Author Commented:
Microsoft Powerpoint 9.0 Object Library is there, but not 11.0.

I'm using Microsoft Visual Studio 2005.
0
 
käµfm³d 👽Commented:
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.
0
 
coperations07Author Commented:
I've already added the 9.0 reference and I still get the same error as above..
0
 
käµfm³d 👽Commented:
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.
0
 
coperations07Author Commented:
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.
0
 
coperations07Author Commented:
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?
0
 
käµfm³d 👽Commented:
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.
0
 
coperations07Author Commented:
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?
0
 
coperations07Author Commented:
I've found a way that works!  Is there anything wrong with opening/closing the slide show using the below code?
I would still like to find which library has the multiple reference b/c I figure it will cause problems later...

thx,
Dave
    Private objProcess As System.Diagnostics.Process
 
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        'start slide show.
        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = "C:\Program Files\American Greetings\SlideShow\Sorter_Show.ppt"
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()
        Catch
            MessageBox.Show("Could not start process " & "C:\Program Files\American Greetings\SlideShow\Sorter_Show.ppt", "Error")
        End Try
 
    End Sub
 
    Private Sub sp_trigger_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sp_trigger.Tick
        'close slide show.
        Try
            objProcess.Kill()
        Catch
            MessageBox.Show("Could not stop process " & "C:\Program Files\American Greetings\SlideShow\Sorter_Show.ppt", "Error")
        End Try
 
    End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now