Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Muk Muk is offline
external usenet poster
 
Posts: 10
Default Check File name for its existance in a folder

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Check File name for its existance in a folder

Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

  #3   Report Post  
Posted to microsoft.public.excel.programming
Muk Muk is offline
external usenet poster
 
Posts: 10
Default Check File name for its existance in a folder

Martin I do not know why this is not working.

Can you guess why?

"Martin Fishlock" wrote:

Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Check File name for its existance in a folder

from dave peterson


dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


--


Gary


"Muk" wrote in message
...
Hi
I want to check for some particular files (Containing some particular
words
like time sheets or April/May 2006€¦.) are already there in a folder or
not.
Can I check I mean search whether the particular file is there in folder
or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk


  #5   Report Post  
Posted to microsoft.public.excel.programming
Muk Muk is offline
external usenet poster
 
Posts: 10
Default Check File name for its existance in a folder

Gary; I am sorry as I believe that I haven't explained my problem correctly.
Your Code is working but really what I want is to find is files which
contain some particular contents of word in the Name.
Like "Timesheets" or "2006" or "January"
and to make a list of the same

Regards,
Muk

"Gary Keramidas" wrote:

from dave peterson


dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


--


Gary


"Muk" wrote in message
...
Hi
I want to check for some particular files (Containing some particular
words
like time sheets or April/May 2006€¦.) are already there in a folder or
not.
Can I check I mean search whether the particular file is there in folder
or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Check File name for its existance in a folder

this will display a message box for all files with 2006 in the name of the
default folder.

add the path you want to check and change 2006 to something you want to
search for
fName = Dir("C:\MyFolder\*2006*.xls")


Option Explicit
Dim fname As String
Sub test()
fname = Dir("*2001*.xls") 'Do While fname < ""
MsgBox fname
fname = Dir()
Loop
End Sub


--


Gary


"Muk" wrote in message
...
Gary; I am sorry as I believe that I haven't explained my problem
correctly.
Your Code is working but really what I want is to find is files which
contain some particular contents of word in the Name.
Like "Timesheets" or "2006" or "January"
and to make a list of the same

Regards,
Muk

"Gary Keramidas" wrote:

from dave peterson


dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


--


Gary


"Muk" wrote in message
...
Hi
I want to check for some particular files (Containing some particular
words
like time sheets or April/May 2006€¦.) are already there in a folder or
not.
Can I check I mean search whether the particular file is there in
folder
or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Check File name for its existance in a folder

It is strange as it works on mine.

Maybe you need a reference set.

What is the error saying?
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Martin I do not know why this is not working.

Can you guess why?

"Martin Fishlock" wrote:

Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

  #8   Report Post  
Posted to microsoft.public.excel.programming
Muk Muk is offline
external usenet poster
 
Posts: 10
Default Check File name for its existance in a folder

Code runs with no files found
I mean ff (Foundfiles) = Empty
NO Error Message

"Martin Fishlock" wrote:

It is strange as it works on mine.

Maybe you need a reference set.

What is the error saying?
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Martin I do not know why this is not working.

Can you guess why?

"Martin Fishlock" wrote:

Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

  #9   Report Post  
Posted to microsoft.public.excel.programming
Muk Muk is offline
external usenet poster
 
Posts: 10
Default Check File name for its existance in a folder

Thanks Gary

This worked and solved my problem

Thank indeed
Regards,
Muk

"Gary Keramidas" wrote:

this will display a message box for all files with 2006 in the name of the
default folder.

add the path you want to check and change 2006 to something you want to
search for
fName = Dir("C:\MyFolder\*2006*.xls")


Option Explicit
Dim fname As String
Sub test()
fname = Dir("*2001*.xls") 'Do While fname < ""
MsgBox fname
fname = Dir()
Loop
End Sub


--


Gary


"Muk" wrote in message
...
Gary; I am sorry as I believe that I haven't explained my problem
correctly.
Your Code is working but really what I want is to find is files which
contain some particular contents of word in the Name.
Like "Timesheets" or "2006" or "January"
and to make a list of the same

Regards,
Muk

"Gary Keramidas" wrote:

from dave peterson


dim teststr as string
teststr = ""
on error resume next
teststr = dir("yourpath\yourfilenamehere")
on error goto 0

if teststr = "" then
'not found
else
'found
end if


--


Gary


"Muk" wrote in message
...
Hi
I want to check for some particular files (Containing some particular
words
like time sheets or April/May 2006€¦.) are already there in a folder or
not.
Can I check I mean search whether the particular file is there in
folder
or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Check File name for its existance in a folder

This one actually looke in the files for the text not the file names.

No problem Gary provided you with a solution.
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Code runs with no files found
I mean ff (Foundfiles) = Empty
NO Error Message

"Martin Fishlock" wrote:

It is strange as it works on mine.

Maybe you need a reference set.

What is the error saying?
--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Martin I do not know why this is not working.

Can you guess why?

"Martin Fishlock" wrote:

Muk

You can use the following, it only searchs for one condition at a time so
you need to devise some logic to keep multiple condition results.
See the line with <<<< in it to change the condition.

Sub fso()
Const msoFileTypeExcelWorkbooks = 4

Dim fs As Object 'FileSearch
Dim ff
Dim lRow As Long

Set fs = Application.FileSearch
fs.LookIn = "C:\Documents and Settings\admin\My Documents"
fs.SearchSubFolders = True
fs.TextOrProperty = "Files" '<<< text to find wilds ok
fs.FileType = msoFileTypeExcelWorkbooks
fs.Execute

For Each ff In fs.FoundFiles
lRow = lRow + 1
ActiveSheet.Cells(lRow, 1) = ff
Next

End Sub

--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"Muk" wrote:

Hi
I want to check for some particular files (Containing some particular words
like time sheets or April/May 2006€¦.) are already there in a folder or not.
Can I check I mean search whether the particular file is there in folder or
not?

Is this possible with a macro code?

Any help on this is much appreciated
Regards,
Muk

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check for file in folder Les Stout[_2_] Excel Programming 2 October 11th 06 07:08 PM
Check for Existance of sheet - problem with UDF PC[_3_] Excel Programming 3 April 8th 05 12:44 PM
How to check for the existance of a Sheet (or not) Pete[_22_] Excel Programming 2 April 5th 05 04:27 PM
error handling - check chart existance annette2002[_2_] Excel Programming 1 June 9th 04 06:03 AM
Existance Check Fails ChuckM[_2_] Excel Programming 7 January 31st 04 03:02 AM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"