• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

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?


0
ncrew
Asked:
ncrew
  • 3
  • 3
  • 2
1 Solution
 
1WilliamCommented:
How about using a shell command?
0
 
Mike77Commented:
Try this :

'declarations
------------------

Private Declare Function ShellExecute Lib "shell32" _
   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 Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31

'code
---------
Call ShellExecute(0&, "open", "c:\path\file.pdf", 0&, 0&, SW_SHOWNORMAL)
0
 
1WilliamCommented:
Like this:
Dim RetVal

RetVal = Shell("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" & " " & "\\ServerName\DirectoryName\FileName.pdf")
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ncrewAuthor Commented:
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.
0
 
1WilliamCommented:
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"
0
 
Mike77Commented:
what if acrobat has not been installed in the default directory?
0
 
ncrewAuthor Commented:
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.
0
 
ncrewAuthor Commented:
I appreciatd the step-by-step solution!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now