Open files from a dynamic path..

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi al..

I have a problem.. I placed the question here last week aswell, unfortunatly
it did not solve my problem..

Scope:
I have a userform where I would like to add some buttons wich open certain
adobe PDF files. Furthermore, this project is to be burned on a CD so it can
be distributed.
My problem are the drive letters.. (diffrent systems, diffrent drive
letters..)

this is the code i'm using..
_______________

Private Sub CommandButton19_Click()
'open pdf file
Dim filelocation As String
filelocation = ThisWorkbook.Path
_________________

I'm missing the last part where I call the variable filelocation and open
the pdf file..
Who can help me out?


--
Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
Arjan,
Depends where the PDFs are relative to the Excel WB. You already have
ThisWorkbook.Path, so if they in a sub folder of that :
ThisWorkbook.Path & "\PDF_Folder\PDF1.pdf"

If you maybe on Mac then you would need to do bit work at detecting that
first.

NickHK
 
Nick,

Thanks for your reply.. The files are in the same path as the workbook.
However, what I don't know is the how to open the file(s)..

what code do I have to use?

Arjan




--
Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
If you just want to open them in the user's defualt app for pdf files :

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

ShellExecute 0, "open", Thisworkbook.path & "\YourPDF.pdf", "", "", 1

NickHK
 
Are you using a fileopen dialog box for the user to select the file?

If not, you could try using it...it will return you the entire path of
the selected file/folder

check FileDialog Property in help.

HTH
-Satish
 
Nick,

Sorry to bother you again..
I tried to insert the code, unfortunalty there's a compile-error which
states that
it expects a rulenumber or a name or a instruction or a instruction-end..

I do have to put the code in the command button sub? Or do I make a mistake?



--
Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
Nick, sorry to bother you again...

When i put this code in the commandbutton sub it returns a complie error.
It suspects a rulenumber, a name an instruction or an instruction end.

I do have tp put this code in the commandbutton sub? or do i make a mistake?

thanks again for your help!

Arjan


--
Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
Arjan,
OK, this a bit more correct :

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

Private Sub CommandButton1_Click()
ShellExecute 0, "open", Thisworkbook.path & "\YourPDF.pdf", "", "", 1
End Sub

NickHK
 
Nick,

thnx!! works great.. you've been a great help!!
--
Arjan Bregman

*****
the knowledge is always there, maybe hidden, but it is there..
*****
 
Back
Top