Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Opening PDFs from VBA??

Hi All,

I am write a simple macro to open a PDF from VBA, but I want the name
of the PDF and location of the PDF as a string value, such that one
could assign the macro to a button in excel and use it when needed.

So far I have:

Sub pdfVBA()
Dim pdfLoc, pdfName As String

'change this to location of directory
pdfLoc = "M:\"

pdfName = ActiveCell.Value

Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe" & _
pdfLoc & pdfName, 1

End Sub

But I am receiving an "File not found" error. I suspect I has
something to do with using the string values, because when I replace
pdfLoc and pdfName with the location and file the code works.

Thanks for any help in advance
Eugene
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Opening PDFs from VBA??

Hi Eugene
Try concatenating both strings with
Dim FullName$
FullName = pdfLoc & pdfName
And then use FullName in your shell command.

HTH
Cordially
Pascal

"Eugene" a écrit dans le message de
om...
Hi All,

I am write a simple macro to open a PDF from VBA, but I want the name
of the PDF and location of the PDF as a string value, such that one
could assign the macro to a button in excel and use it when needed.

So far I have:

Sub pdfVBA()
Dim pdfLoc, pdfName As String

'change this to location of directory
pdfLoc = "M:\"

pdfName = ActiveCell.Value

Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe" & _
pdfLoc & pdfName, 1

End Sub

But I am receiving an "File not found" error. I suspect I has
something to do with using the string values, because when I replace
pdfLoc and pdfName with the location and file the code works.

Thanks for any help in advance
Eugene



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Opening PDFs from VBA??

Hi Eugene,

You need to include a space between the program path and the file path and
you probably also need to generate quotes around the file path. Try the
following:

Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe """ & _
pdfLoc & pdfName & """", 1

Copy the above code to a module to see more clearly what is there. The
embedded quotes are doubled and there is a space after .exe

John Green


"Eugene" wrote in message
om...
Hi All,

I am write a simple macro to open a PDF from VBA, but I want the name
of the PDF and location of the PDF as a string value, such that one
could assign the macro to a button in excel and use it when needed.

So far I have:

Sub pdfVBA()
Dim pdfLoc, pdfName As String

'change this to location of directory
pdfLoc = "M:\"

pdfName = ActiveCell.Value

Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe" & _
pdfLoc & pdfName, 1

End Sub

But I am receiving an "File not found" error. I suspect I has
something to do with using the string values, because when I replace
pdfLoc and pdfName with the location and file the code works.

Thanks for any help in advance
Eugene



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Opening PDFs from VBA??

I find the following approach to be quite flexible. Not only will it take
PDF, but any type of document (.doc, .hlp, .txt, .pdf, etc...) - including
URLs.

In a standard module:

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

Sub OpenPDF()
ShellExecute 0, "Open", ActiveCell.Value, vbNullString, vbNullString,
vbNormalFocus
End Sub

Assign Macro to OpenPDF


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Eugene" wrote in message
om...
Hi All,

I am write a simple macro to open a PDF from VBA, but I want the name
of the PDF and location of the PDF as a string value, such that one
could assign the macro to a button in excel and use it when needed.

So far I have:

Sub pdfVBA()
Dim pdfLoc, pdfName As String

'change this to location of directory
pdfLoc = "M:\"

pdfName = ActiveCell.Value

Shell "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe" & _
pdfLoc & pdfName, 1

End Sub

But I am receiving an "File not found" error. I suspect I has
something to do with using the string values, because when I replace
pdfLoc and pdfName with the location and file the code works.

Thanks for any help in advance
Eugene



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controling Acrobat PDFs YS Excel Discussion (Misc queries) 1 December 18th 04 10:47 AM
Relative Hyperlinks to PDFs (or other documents) || cypher || Excel Discussion (Misc queries) 1 November 30th 04 03:05 AM
Relative Hyperlinks to PDFs (and other documents) || cypher || Links and Linking in Excel 0 November 30th 04 02:01 AM
Printing one Adobe pdf instead of multiple pdfs universal[_27_] Excel Programming 1 April 7th 04 01:16 PM
Loading PDFs, Shell Function Paul Martin Excel Programming 5 July 31st 03 02:52 AM


All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"