ShellExecute VBA

Posted on 2014-01-10
Medium Priority
Last Modified: 2014-01-10
Hi Experts,

I'm using this VBA code and I'm trying to open a pdf file from MS Access 2007 form.

Private 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

If I use this line no issues:

ShellExecute 0, "Open", "C:\Temp\myfile.pdf", "", "", vbNormalNoFocus

However this is what I need since the path name can change..

filename=CurrentProject.Path & "\myfile.pdf"

ShellExecute 0, "Open", filename, "", "", vbNormalNoFocus

Is that possible ?

Thank you,
Question by:valixpacc
  • 3
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39771163
have you tried

followhyperlink CurrentProject.Path & "\myfile.pdf"

if you want to use shell, you need to know the path to your pdf (acrobat ) reader
LVL 54

Assisted Solution

Rgonzo1971 earned 450 total points
ID: 39771180

You could declare Filename like this
Dim filename as String at the beginning of the code after the "sub" of function

Otherwise ther is no reason it won't function

LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39771243
i think rgonzo is correct, sorry misread your post.

Author Comment

ID: 39771389
Thank you for your answers.
I already did that ( all variables are declared).
This won't solve the problem even I specify the full path of Acrobat Reader.

Again I wil explain:

Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"

 '' no problem here

Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & "C:\Temp\myfile.pdf", vbNormalFocus

'' this is not working

Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & filename, vbNormalFocus


Application.FollowHyperlink "C:\Temp\myfile.pdf" -- working

Application.FollowHyperlink filename -- not working

So looks like no matter what approach I choose I need to specify the name of the file and the path instead of a variable wich doesn't solve the  issue.
LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 1050 total points
ID: 39771498
are you sure there is a pdf file in the folder where your db application is located?

Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"

debug.print filename

do this checking..

dim fName
fName= dir(currentproject.path & "\*.pdf")
while fName <>""
    debug.print currentproject.path & "\" & fName

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question