Solved

How to close Adobe Reader in code?

Posted on 2007-03-28
4
187 Views
Last Modified: 2013-11-25
Hi,

I am using following code to print a pdf file from a windows app. The requirement is to close the acrobat view after the print. When I step through it, the

  MyProcess.CloseMainWindow()
will do the trick, but in real time, it dose not close the viewer.

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
           Dim MyProcess As New System.Diagnostics.Process
           MyProcess.StartInfo.FileName = "c:\OrderForm.pdf"
           MyProcess.StartInfo.UseShellExecute = True
        MyProcess.StartInfo.Verb = "Print"
        MyProcess.Start()
        MyProcess.CloseMainWindow()
        Me.Close()
    End Sub
0
Comment
Question by:ommer
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18821523
You may just need a small pause before closing the app...

        MyProcess.Start()
        System.Threading.Thread.Sleep(2000) ' two second pause
        MyProcess.CloseMainWindow()
        Me.Close()
0
 

Author Comment

by:ommer
ID: 18822919
Ok, I can see your point. But how to pause?

I have treid
 MyProcess.WaitForExit(10000)

The me.close has been delayed for 10 seconds, but the viewer did not close.

Thanks!
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 18823887
What do you mean "But how to pause?"...

I put it right there in the code example I gave:

        MyProcess.Start() ' start the process
        System.Threading.Thread.Sleep(10000) ' ten second pause
        MyProcess.CloseMainWindow() ' NOW try closing the main window?
        Me.Close() ' close the form

I suppose you can do it this way as well:

        MyProcess.Start()
        MyProcess.WaitForExit(10000)
        If Not MyProcess.HasExited Then
            MyProcess.CloseMainWindow()
        End If
        Me.Close()
0
 

Author Comment

by:ommer
ID: 18824143
That worked (the first one).
I thought you meant to insert a pause between CloseMainWindow() and me.close().
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

856 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