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

Hi,

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");
adobe.Show;

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.

Thanks
sbatadaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
4ceReconSniperCommented:
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
0
rdwillettCommented:
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
   
err_exitfunction:
    MsgBox Err.Description, vbInformation, "Error Open Association"
    Exit Sub
End Sub

Private Sub Command1_Click()
    runappfile
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

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.