Link to home
Start Free TrialLog in
Avatar of ncrew
ncrew

asked on

Acc97 -Opening an adobe file through VB code

Here is my code that works when I want to open a Word Doc.

Dim oApp As Object
     
    On Error Resume Next
    Set oApp = GetObject(, "word.Application")
    If Err.Number <> 0 Then MsgBox (Err.Description)
    Err.Clear
    Set oApp = GetObject ("\\ServerName\DirectoryName\FileName.doc")
    If Err.Number <> 0 Then MsgBox (Err.Description)
 
    Err.Clear
    oApp.Application.Visible = True
    oApp.Parent.Windows(1).Visible = True

    Set oApp = Nothing

If I try to change the class to
     Set oApp = GetObject(, "Acrobat.Application")
and the file name to
    Set oApp = GetObject ("\\ServerName\DirectoryName\FileName.pdf")
I get the following error message

     "ActiveX componet cannot create object"

How can I open a pdf file using VB code?


Avatar of 1William
1William

How about using a shell command?
ASKER CERTIFIED SOLUTION
Avatar of Mike77
Mike77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Like this:
Dim RetVal

RetVal = Shell("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" & " " & "\\ServerName\DirectoryName\FileName.pdf")
Avatar of ncrew

ASKER

I'm open to suggestions, but I'll need "hand holding".  I don't know what you mean by shell command or how to execute it.
Take my second suggestion and change the path information to suit.  The first part is the path to acrobat
("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe"

and the second is to the PDF
"\\ServerName\DirectoryName\FileName.pdf"
what if acrobat has not been installed in the default directory?
Avatar of ncrew

ASKER

Gentlemen, you're both my heros.  I am selecting Mike's answer because the Adobe software resides on a server and I don't have the exact location; using his code, I did not need it.

Thank you both.
Avatar of ncrew

ASKER

I appreciatd the step-by-step solution!