Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default .Foundfiles Question

Hi all,

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default .Foundfiles Question

Not tested

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
Activeworkbook.SaveAs "D:\" & Activeworkbook.Name
Activeworkbook.Close Savechanges:=False
Next i
Else
MsgBox "There were no files found."
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shane" wrote in message
...
Hi all,

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
Thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default .Foundfiles Question

thanks bob,
can we simply copy the files without actually having to open them. much like
a copy and past behind the scene?


"Bob Phillips" wrote in message
...
Not tested

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
Activeworkbook.SaveAs "D:\" & Activeworkbook.Name
Activeworkbook.Close Savechanges:=False
Next i
Else
MsgBox "There were no files found."
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shane" wrote in message
...
Hi all,

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
Thanks






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default .Foundfiles Question

"Shane" wrote in message
...

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

[...]

Simply replace your IF clause with the following:
====================================
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) Then
For i = 1 To .FoundFiles.Count
FileCopy .FoundFiles(i), "C:\Prova\" & _
Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1)
Next i
Else
MsgBox "There were no files found."
End If
====================================
Ciao
Bruno


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default .Foundfiles Question

Hi Shane,

Yes, this alternative way

'---------------------------------------------------------------------------
Sub CopyFolder()
'---------------------------------------------------------------------------
Dim oFSO As Object
Dim sFolderSource As String
Dim sFolderTarget As String

Set oFSO = CreateObject("Scripting.FileSystemObject")
sFolderSource = "C:\My Documents"
sFolderTarget = "D:\Data"
If oFSO.FolderExists(sFolderSource) Then
If Not oFSO.FolderExists(sFolderTarget) Then
MkDir sFolderTarget
End If
oFSO.CopyFolder sFolderSource, sFolderTarget & "\"
End If
Set oFSO = Nothing
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shane" wrote in message
...
thanks bob,
can we simply copy the files without actually having to open them. much

like
a copy and past behind the scene?


"Bob Phillips" wrote in message
...
Not tested

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
Activeworkbook.SaveAs "D:\" & Activeworkbook.Name
Activeworkbook.Close Savechanges:=False
Next i
Else
MsgBox "There were no files found."
End If


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shane" wrote in message
...
Hi all,

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

Set fs = Application.FileSearch
With fs
.NewSearch
.LookIn = "C:\My Documents"
.Filename = "*.doc"
.SearchSubFolders = True
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles


If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
' MsgBox "There were " & .FoundFiles.Count & _
' " file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
Thanks










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default .Foundfiles Question

thank you all so much!!!


"Bruno Campanini" wrote in message
...
"Shane" wrote in message
...

Would you be able to advise how I could copy the files found by the
following macro to a another directory - say D:\Data

[...]

Simply replace your IF clause with the following:
====================================
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) Then
For i = 1 To .FoundFiles.Count
FileCopy .FoundFiles(i), "C:\Prova\" & _
Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1)
Next i
Else
MsgBox "There were no files found."
End If
====================================
Ciao
Bruno




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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 07:15 AM.

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

About Us

"It's about Microsoft Excel"