Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening drawings saved in a PDF format 3

Status
Not open for further replies.

TonyCro

Mechanical
Jan 12, 2005
23
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.

 
Replies continue below

Recommended for you

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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor