ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search for a specific file's extension (https://www.excelbanter.com/excel-programming/372519-search-specific-files-extension.html)

2007-User

Search for a specific file's extension
 
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.



moon[_6_]

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.




2007-User

Search for a specific file's extension
 
wow, this is so good
thank you so much.


"moon" <6369706865725F6475646540706C616E65742E6E6C wrote in message
. ..
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.






2007-User

Search for a specific file's extension
 
Moon!,
It gives me an error on this line :
Set fso = CreateObject("Scripting.FileSystemObject")

the error is "ActiveX component can't create objects"

Do you know why I am getting this message?

Thanks.




"moon" <6369706865725F6475646540706C616E65742E6E6C wrote in message
. ..
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.






[email protected]

Search for a specific file's extension
 
Hi,

That "Scripting.FileSystemObject" must be use Reference:

Microsoft Scripting Runtime

Just check your ToolsReferences commandbar of VBE
Regards,

Halim


2007-User menuliskan:
Moon!,
It gives me an error on this line :
Set fso = CreateObject("Scripting.FileSystemObject")

the error is "ActiveX component can't create objects"

Do you know why I am getting this message?

Thanks.




"moon" <6369706865725F6475646540706C616E65742E6E6C wrote in message
. ..
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.





Jim Cone

Search for a specific file's extension
 
The ScriptingRuntime FileSystemObject is included with
all Windows operating systems released after Windows 95.
It is not available on a Mac or the older Windows systems.
Sometimes it is necessary to re-registering the scrrun.dll with windows.
To register it, press the windows Start Button and choose Run.
Then in the Text Box type:
regsvr32 "C:\WINDOWS\system32\scrrun.dll"
Click OK
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"2007-User"

wrote in message
Moon!,
It gives me an error on this line :
Set fso = CreateObject("Scripting.FileSystemObject")
the error is "ActiveX component can't create objects"
Do you know why I am getting this message?
Thanks.

Tom Ogilvy

Search for a specific file's extension
 
CreateObject is used when you don't create a reference.

However, if attempted, the inability to create the reference should
reinforce the fact that the scripting runtime is not registered.

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
Hi,

That "Scripting.FileSystemObject" must be use Reference:

Microsoft Scripting Runtime

Just check your ToolsReferences commandbar of VBE
Regards,

Halim


2007-User menuliskan:
Moon!,
It gives me an error on this line :
Set fso = CreateObject("Scripting.FileSystemObject")

the error is "ActiveX component can't create objects"

Do you know why I am getting this message?

Thanks.




"moon" <6369706865725F6475646540706C616E65742E6E6C wrote in message
. ..
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.







2007-User

Search for a specific file's extension
 
Thanks for all of your responses.


"Jim Cone" wrote in message
...
The ScriptingRuntime FileSystemObject is included with
all Windows operating systems released after Windows 95.
It is not available on a Mac or the older Windows systems.
Sometimes it is necessary to re-registering the scrrun.dll with windows.
To register it, press the windows Start Button and choose Run.
Then in the Text Box type:
regsvr32 "C:\WINDOWS\system32\scrrun.dll"
Click OK
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"2007-User"

wrote in message
Moon!,
It gives me an error on this line :
Set fso = CreateObject("Scripting.FileSystemObject")
the error is "ActiveX component can't create objects"
Do you know why I am getting this message?
Thanks.





All times are GMT +1. The time now is 02:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com