Solved

Close external application

Posted on 2009-04-08
14
1,864 Views
Last Modified: 2012-05-06
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
Comment
Question by:coperations07
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24101025
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
 

Author Comment

by:coperations07
ID: 24101357
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
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 150 total points
ID: 24101396
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:coperations07
ID: 24101756
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24101798
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
 

Author Comment

by:coperations07
ID: 24101931
Microsoft Powerpoint 9.0 Object Library is there, but not 11.0.

I'm using Microsoft Visual Studio 2005.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24101952
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
 

Author Comment

by:coperations07
ID: 24102214
I've already added the 9.0 reference and I still get the same error as above..
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24103503
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
 

Author Comment

by:coperations07
ID: 24106888
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
 

Author Comment

by:coperations07
ID: 24111460
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
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24111786
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
 

Author Comment

by:coperations07
ID: 24130009
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
 

Accepted Solution

by:
coperations07 earned 0 total points
ID: 24130521
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

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question