×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Opening drawings saved in a PDF format
3

Opening drawings saved in a PDF format

Opening drawings saved in a PDF format

(OP)
We have a simple spreadsheet that we log memos and other similar documents in and with some code to open these documents in word - and we're looking to see if we can have something similar for opening drawings saved in a PDF format.  Unfortunately the code was written by a chap who has moved on and I have absolute zero experience in this field

 

The code we have for opening the word docs is;

 
------------------------------------------------------------

Code BlockOption Explicit
Dim Wordfile, Mypath, Mydir, Myfile, MyfilePath, Myappid, Author, Yr, Check, Response, Wordapp

Sub view_document()

On Error GoTo Errorhandler          'trap errors for processing
    
    Wordfile = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE "
'Set drive
    Mypath = (Left(ActiveWorkbook.FullName, 2))
'Set directory for document dependent on which sheet user is on.
    If ActiveSheet.Name = "Engineering Reports" Then
       Mydir = "\Engineering\Engineering Reports\Engineering Reports +600\"
    ElseIf ActiveSheet.Name = "Memo's" Then
       Mydir = "\Engineering\Engineering Reports\Memo's\"
    ElseIf ActiveSheet.Name = "DI's" Then
       Mydir = "\Engineering\Engineering Reports\DI\"
    End If
    
'set document user wishes to open
    Myfile = ActiveSheet.Cells(ActiveCell.Row, "A")
    MyfilePath = Mypath & Mydir & Myfile & ".doc"
    Set Wordapp = CreateObject("Word.Application")
' Set Word to be visible and call up document
    With Wordapp
       .Visible = True
       .documents.Open MyfilePath
    End With

 
----------------------------------------------------------
 


and I tried the following changes;

 


Code BlockOption Explicit
Dim PDFfile, Mypath, Mydir, Myfile, MyfilePath, Myappid, Author, Yr, Check, Response, PDFapp

Sub view_document()

On Error GoTo Errorhandler          'trap errors for processing
    
    PDFfile = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
'Set drive
    Mypath = (Left(ActiveWorkbook.FullName, 2))
'Set directory for document dependent on which sheet user is on.
    If ActiveSheet.Name = "drawings" Then
       Mydir = "\drawings\drawing list\"
    End If
    
'set document user wishes to open
    Myfile = ActiveSheet.Cells(ActiveCell.Row, "A")
    MyfilePath = Mypath & Mydir & Myfile & ".pdf"
    Set PDFapp = ("PDF.application")
' Set Word to be visible and call up document
    With PDFapp
       .Visible = True
       .documents.Open MyfilePath
    End With
End

 

Since it's clear I'm in way over my head, I'm hoping that you wonderful peeps might be willing to point me in the right direction.

 

Many thanks

Tony.

RE: Opening drawings saved in a PDF format

I've modified your attempt with some code that will work if Acrobat is installed to the same location on every PC.  If there is code later that actually tries to manipulate the Word files it will not work.  All this will do is open the Acrobat file in a maximized window.  I am assuming that everything up to the "Set PDFapp =..." line works properly.  That is to say, MyfilePath actually contains a string that is the path to the PDF you want to open.  You can comment out the MsgBox line once you verify that the file path is being built correctly.

CODE

Code BlockOption Explicit
Dim PDFfile, Mypath, Mydir, Myfile, MyfilePath, Myappid, Author, Yr, Check, Response, PDFapp

Sub view_document()

On Error GoTo Errorhandler          'trap errors for processing
    
    PDFfile = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
'Set drive
    Mypath = (Left(ActiveWorkbook.FullName, 2))
'Set directory for document dependent on which sheet user is on.
    If ActiveSheet.Name = "drawings" Then
       Mydir = "\drawings\drawing list\"
    End If
    
'set document user wishes to open
    Myfile = ActiveSheet.Cells(ActiveCell.Row, "A")
    MyfilePath = Mypath & Mydir & Myfile & ".pdf"
    MsgBox "MyfilePath variable contains the string:" & _
      vbcrlf & vbcrlf & myfilepath & vbcrlf & vbcrlf & _
      "Attempting to open with Acrobat Reader."
    shell """" & PDFfile & """ """ & MyfilePath & """", vbMaximizedFocus
End

RE: Opening drawings saved in a PDF format

2
This same task can be accomplished with hyperlinks.  What I do is prepare a list of the pdf files in a single column.  The list should have the full path name of the file.  Then select all the cells with file names and run the following code.

CODE

Sub ConvertSelectedFilesToHyperlinks()
For Each cl In Selection
    ActiveSheet.Hyperlinks.Add Anchor:=cl, Address:=cl.Text
Next
End Sub
It converts the path to a hyperlink.  Now clicking the link should open the file provided your user has the releveant application registered/installed on their computer.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources