View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
moon[_6_] moon[_6_] is offline
external usenet poster
 
Posts: 43
Default Search for a specific file's extension

This should work after a buttonclick...

Option Explicit

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 Worksheet_Button_SearchECW_Click()
Dim searchPath, ecwFile As String
Dim fso, fs, fc, f
searchPath = ThisWorkbook.Path & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fs = fso.GetFolder(searchPath)
Set fc = fs.Files
For Each f In fc
If Right(f.Name, 4) = ".ECW" Then
ecwFile = f.Name
Exit For
End If
Next f
Set f = Nothing
Set fc = Nothing
Set fs = Nothing
Set fso = Nothing
ShellExecute vbNull, vbNullString, ecwFile, vbNullString, searchPath, 1
End Sub



"2007-User" schreef in bericht
...
Hi Guys,

I need a VBA to be able to search for a file with specific extension (like
"ecw"),
and have another application to open that file.
(search for the file can be in the same directory that the correct open
excel file is existing)

How this is possible?
Any help would be appreciated.