Open a pdf file from a local drive using Adobe Acrobat Reader using OLE object.

Posted on 2004-11-12
Last Modified: 2013-12-03

We are using the Brio reporting software and I have a command button which when clicked will tell Brio to export the report in pdf format to the c drive. I can use the Application.Shell(App, Agrs) method to open Adobe Acrobat Reader and the saved pdf file from the C drive. Hoever this requires me to hard code the path to the AcroRd32.exe and this is a problem as different users may have different Adobe Reader versions. Thus I am trying to open Acrobat Reader using OLE object and am able to open it using the following two commands :
adobe = new OLEObject("AcroExch.App");

However I am unable to tell it to get the test .pdf file form C:\Test.Pdf and display it.

Can anybody please tell me how I can do this.

Question by:sbatada
    LVL 28

    Accepted Solution

    Have you tried shellexecute api:

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Private Sub Command1_Click()
    Call ShellExecute(hwnd, "Open", ("C:\Somefile.pdf"), "", "", 1)
    End Sub
    LVL 3

    Expert Comment

    yeah that is the same way i did and i agree to his solution, but the acrobat.exe is left in the processes bar on yout task manager, ask vinnyd79 how to close it
    LVL 4

    Assisted Solution

    Try this:
    Create a new vb exe project
    Add a form
    Add a command button named Command1 (default name)
    use the following code

    Private Declare Function FindExecutable _
        Lib "shell32.dll" Alias "FindExecutableA" _
        (ByVal lpFile As String, _
        ByVal lpDirectory As String, _
        ByVal lpResult As String) As Long

    Public Sub runappfile()
        Dim strname As String
        Dim strResult As String
        Dim lngResult As Long
        Dim i, s_msg
        On Error GoTo err_exitfunction
        strname = "C:\instructions.pdf"  '-----------------> put your filename here
        strResult = String(255, 0)
        lngResult = FindExecutable(strname, vbNullString, strResult)
        strResult = Trim(Replace(strResult, "/dde", "", 1))
        'run the file and not an .exe file
        i = Shell(Trim(Replace(strResult, vbNullChar, "", 1)) & " " & strname, 1)
        Exit Sub
        MsgBox Err.Description, vbInformation, "Error Open Association"
        Exit Sub
    End Sub

    Private Sub Command1_Click()
    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    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…

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now