PDA

View Full Version : List files in a folder and open using correct app



lifeson
12-06-2007, 03:32 AM
Hi all
I have a project which lists filters a list of components (boilers)
A user can select a component and oprn a second user form to show specific detail about the boiler.
I want to be able to add the ability for a lsit box to display various documents (which can be .pdf or .doc etc) relating to that specific boiler in a list box, if the user selects one from the list, the doc will open in the correct application.
I this possible?/
I have the docs stored in a file structure based on the make and model of the boiler and have this to determine the correct file path

Dim fPathDocs As String
fPathDocs = ThisWorkbook.path & "\Documents\" & sman & "\" & sModel & "\.*"

With lstDocs
.AddItem 'just document name required????
End With


Tanks for looking, hope you can help

rory
12-06-2007, 05:08 AM
Something like:

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
String, ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&
Dim fPathDocs As String
Function StartDoc(DocName As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
"", "C:\", SW_SHOWNORMAL)
End Function
Private Sub CommandButton1_Click()
StartDoc fPathDocs & "\" & lstDocs.Value
End Sub
Private Sub LoadList()
Dim strFile As String
fPathDocs = ThisWorkbook.path & "\Documents\" & sman & "\" & sModel
strFile = Dir(fPathDocs & "\*.*")
Do Until strFile = ""
With lstDocs
.AddItem strFile
strFile = Dir
End With
Loop
End Sub


should get you started.

lifeson
12-06-2007, 08:21 AM
Thanks Rory :clap: :clap: :bow:
Not sure how you ve done it but it works on a test sheet, now I have got to try and incorporate it into my project without screwing it all up :rotlaugh: :rotlaugh: :rofl: :bug: