Open a PDF from Excel

Michael Pettinicchi

Board Regular
Joined
Apr 11, 2002
Messages
53
I posted this before but didn't get any answers so I'm trying it again just in case it was missed.

I need to open a PDF file from an Excel workbook.
It seems I need to create an Object like:
Set appWD = CreateObject("Word.Application")
but I don't know what it should be for a PDF.
Thanks,
Michael
 
Hi Mark,

Thanks for taking Your time to explain it :)

Please try following in order to open a PDF:

<pre>
Option Explicit
Public 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

Sub test()
ShellExecute 0, "open", "e:Datahantering.pdf", "", "", 1
End Sub
</pre>

Kind regards,
Dennis
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Thanks Dennis. That works brilliantly with my configuration.

Kind regards,

Mike
 
Upvote 0
Hi Mike,

My apologize, I notice now that I addressed the emssage to wrong person :(

But I´m glad that we worked it out :)

Kind regards,
Dennis
 
Upvote 0
This is an old post but I was still having problems with this.

Here is what I came up with. The nice thing about this method for me is sometimes the document I need to open is a word document or wordperfect document or an adobe or an excel ect... this way works for all of them.

Create a hyperlink to the file.

Sub hyperlink_test()
Dim MyWorkBook
MyWorkBook = ActiveWorkbook.Name
ProcNum = "7723B" ' define the procedure number to find usually
Sheets("PROCEDURELIST").Select ' blank page
Cells.ClearContents ' Clear last lookup
With Application.FileSearch
.NewSearch
.LookIn = "D:\PROCEDURES\pdf only" 'define director
.SearchSubFolders = True 'look in subdirectorys
.Filename = "*.*" 'search string
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
End With
' list files on sheet
With Application.FileSearch
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Cells(i + 1, 1) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
Exit Sub
End If
End With
'
With ActiveSheet.Range("a1:a5000")
Set C = .Find(ProcNum, LookIn:=xlFormulas) ' ProcNum is the file to find a open
If Not C Is Nothing Then
firstaddress = C.Address
Range(firstaddress).Select
Else
Exit Sub
End If
End With
ActiveSheet.Hyperlinks.Add Anchor:=Range("a1"), Address:=ActiveCell.Text 'create hyperlink to file
Range("a1").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True 'open file
Workbooks(MyWorkBook).Activate
Range("a1").ClearContents
Sheets("loopref").Select
End Sub
 
Upvote 0
Mr_Excel´s routine in Word

Hello.

I can´t get your tip to work, there is an error message at the public declare that states that I'm not allowed to do that. If I change to Private declare the code is OK but nothing opens. Is this a problem regarding office 2003 or is there a differens in word ??

//Mattias
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,937
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top