Solved

Close external application

Posted on 2009-04-08
14
1,820 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
  • 8
  • 6
14 Comments
 
LVL 74

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 74

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
 

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 74

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 74

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 74

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 74

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now