How to load a PDF using Excel VBA

G

Guest

How to load a PDF using Excel VBA? Can anyone give sample code

Many thanks in advance!
 
F

Frank Kabel

Hi
what do you mean with 'load PDF'. Note: Its not so easy to convert a
PDF document back to an Excel file format (has nothing to do with VBA)
 
G

Guest

I mean, I got a PDF file. I want to use Excel VBA to open that PDF in Acrobat Reader. Just like when you double-click a PDF using the mouse
 
D

Dave Peterson

You could search google for pdf translators (to excel or to text files). Most
are commercial ($).

You might get lucky and be able to copy each column and paste into excel (column
by column)--from Adobe Reader.
 
G

Guest

I want to open the PDF in Acrobat Reader, not importing it into Excel. But use Excel VBA


----- Dave Peterson wrote: ----

You could search google for pdf translators (to excel or to text files). Mos
are commercial ($)

You might get lucky and be able to copy each column and paste into excel (colum
by column)--from Adobe Reader



James wrote
 
G

Guest

I tried before I submit the question. Failed

But thanks anyway. :

----- Dave Peterson wrote: ----

Ahhh

maybe something like

Shell "start myfile.pdf

James wrote
 
B

Bill Renaud

I could not get this to work until I included the full path and name of the
Adobe Acrobat reader in the command along with the desired file name.
Apparently, Shell passes the whole string directly to the command engine
without looking up the association in the registry. This could be a problem
if you are going to try to run this on a variety of machines, since the
Adobe Reader may be in different subdirectories on every machine.

Shell "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe C:\My
Documents\Test Page.pdf", _
vbNormalFocus

(You can replace the vbNormalFocus with vbMaximizedFocus or whatever value
you want for the window style.)
--
Regards,
Bill


James said:
I tried before I submit the question. Failed.

But thanks anyway. :>

----- Dave Peterson wrote: -----

Ahhh.

maybe something like:

Shell "start myfile.pdf"
PDF in Acrobat Reader. Just like when you double-click a PDF using the
mouse.
 
F

Frank Kabel

Hi James
o.k. that's simple :)
have a look at the VBA Shell method. e.g.
Shell "mypdffile.pdf"
 
B

Bill Renaud

:
<<Shell "mypdffile.pdf">>

Does this really work on your machine? I had trouble with this (Win ME and
Excel 2000 SP-3).
(See my post about an hour before yours.)
(Need to resynchronize your newsreader every 15 minutes or so?)
 
D

Dave Peterson

Chip Pearson posted an API solution to find the executable (modified very
slightly for pdf):

Option Explicit

Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long

Declare Function FindExecutable Lib "shell32.dll" _
Alias "FindExecutableA" ( _
ByVal lpFile As String, _
ByVal lpDirectory As String, _
ByVal lpResult As String) As Long

Sub AAA()

Dim FName As String
Dim FNum As String
Dim ExeName As String
Dim Res As Long
FName = String$(255, " ")
ExeName = String$(255, " ")
Res = GetTempFileName(CurDir, "", 0&, FName)
FName = Application.Trim(FName)
Mid$(FName, Len(FName) - 2, 3) = "pdf"
FNum = FreeFile
Open FName For Output As #FNum
Close #FNum
Res = FindExecutable(FName, vbNullString, ExeName)
Kill FName
If Res > 32 Then
' association found
ExeName = Left$(ExeName, InStr(ExeName, Chr(0)) - 1)
Else
' no association found
ExeName = ""
End If
MsgBox ExeName

End Sub



Bill said:
I could not get this to work until I included the full path and name of the
Adobe Acrobat reader in the command along with the desired file name.
Apparently, Shell passes the whole string directly to the command engine
without looking up the association in the registry. This could be a problem
if you are going to try to run this on a variety of machines, since the
Adobe Reader may be in different subdirectories on every machine.

Shell "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe C:\My
Documents\Test Page.pdf", _
vbNormalFocus

(You can replace the vbNormalFocus with vbMaximizedFocus or whatever value
you want for the window style.)
--
Regards,
Bill

James said:
I tried before I submit the question. Failed.

But thanks anyway. :>

----- Dave Peterson wrote: -----

Ahhh.

maybe something like:

Shell "start myfile.pdf"
PDF in Acrobat Reader. Just like when you double-click a PDF using the
mouse.
 
D

Dave Peterson

Are you sure that the pc has Reader installed?

Another option (also worked for me):

ActiveWorkbook.FollowHyperlink "c:\myfolder\myfile.pdf"

(Did you include the complete path when you tested the Start suggestion?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top