Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a number of directories containing mainly word documents (but some xls
and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Dave
Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Test this one for me Dave
Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'll give it a try tomorrow, thanks in advance for your help.
Dave "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I seem to have a problem with this but can't work out why...
The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try to test it tomorrow on a lot of files on my system Dave.
Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I wonder if the problem is related to date formats - I am in the UK so all my
dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
With no testing at all...
this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Dave/Dave
On my US machine both give the same result but on my Dutch machine with the Dutch date format not (dmy) You must use dateserial like Dave posted -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... With no testing at all... this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
And dim Fdate as Date
-- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave/Dave On my US machine both give the same result but on my Dutch machine with the Dutch date format not (dmy) You must use dateserial like Dave posted -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... With no testing at all... this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Oops. I didn't notice the declaration.
Ron de Bruin wrote: And dim Fdate as Date -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave/Dave On my US machine both give the same result but on my Dutch machine with the Dutch date format not (dmy) You must use dateserial like Dave posted -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... With no testing at all... this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson -- Dave Peterson |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I add the example to the page
http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... Oops. I didn't notice the declaration. Ron de Bruin wrote: And dim Fdate as Date -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave/Dave On my US machine both give the same result but on my Dutch machine with the Dutch date format not (dmy) You must use dateserial like Dave posted -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... With no testing at all... this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson -- Dave Peterson |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Many thanks for both of your help - it works a treat now.
"Ron de Bruin" wrote: I add the example to the page http://www.rondebruin.nl/folder.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... Oops. I didn't notice the declaration. Ron de Bruin wrote: And dim Fdate as Date -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave/Dave On my US machine both give the same result but on my Dutch machine with the Dutch date format not (dmy) You must use dateserial like Dave posted -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Peterson" wrote in message ... With no testing at all... this If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then looks like it should be more like: If Fdate = dateserial(2006,11,1) And Fdate <= dateserial(2006,11,7) Then Dave Shaw wrote: I wonder if the problem is related to date formats - I am in the UK so all my dates are dd/mm/yyyy. The code appears to copy files (when the criteria is not met) if the above date format would not be consistent with the US mm/dd/yyy. If that does not make sense here are a few examples, the criteria is to copy if date is after 8/11/06 (8 Nov 2006) 7/11/06 - does not copy - i.e. the criteria works 23/10/06 - would copy i.e. the criteria does not work 12/10/06 does not copy - i.e. the criteria works i.e. if the day is 13 or over. "Ron de Bruin" wrote: Try to test it tomorrow on a lot of files on my system Dave. Maybe others see the problem in my code example ? Bed time for me now -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I seem to have a problem with this but can't work out why... The macro seems to work fine until it reaches the third document in the directory. For some reason it then tries to copy this document even though the criteria is not met. Stepping into the macro shows that the Fdate is "22/09/2006" and the criteria is = Date - 5. This also seems to happen for a few other files but not sure why. "Ron de Bruin" wrote: Test this one for me Dave Change thye dates If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then Or use this for the files from the last 30 days If Fdate = Date - 30 Then Sub Copy_Files_Dates() 'This example copy all files between certain dates from FromPath to ToPath. 'You can also use this to copy the files from the last 30 days 'If Fdate = Date - 30 Then 'Note: If the files in ToPath already exist it will overwrite existing files in this folder Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim Fdate As String Dim FileInFromFolder As Object FromPath = "C:\Data" '<< Change ToPath = "C:\Test" '<< Change If Right(FromPath, 1) < "\" Then FromPath = FromPath & "\" End If If Right(ToPath, 1) < "\" Then ToPath = ToPath & "\" End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If If FSO.FolderExists(ToPath) = False Then MsgBox ToPath & " doesn't exist" Exit Sub End If For Each FileInFromFolder In FSO.getfolder(FromPath).Files Fdate = Int(FileInFromFolder.DateLastModified) If Fdate = "11/1/2006" And Fdate <= "11/7/2006" Then FileInFromFolder.Copy ToPath End If Next FileInFromFolder MsgBox "You can find the files from " & FromPath & " in " & ToPath End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "Ron de Bruin" wrote in message ... Hi Dave Yes this is possible I try to add a example this evening to the site -- Regards Ron de Bruin http://www.rondebruin.nl "Dave Shaw" wrote in message ... I have a number of directories containing mainly word documents (but some xls and INI files) that I need to replicate on other network locations. I have created a macro that copies the relevant folders to the relevant servers. However as there are circa 2000 documents that are replicated on 8 different servers it takes a very long time to update. What I wanted to know was whether I could change the macro to only copy files modified between certain dates. The code I am using is based upon the Sub Copy_Folder() macro found at http://www.rondebruin.nl/folder.htm. ; This is copied several times to copy different directories to different loactions (as I am rubbish at loops). Any help would be appreciated. Thanks Dave -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to copy and paste over existing files | Excel Discussion (Misc queries) | |||
Macro 4 copy & paste between 2 books/files | Excel Discussion (Misc queries) | |||
Macro to create a folder and copy files | New Users to Excel | |||
using macro, how can i copy similar fields from other xls files? | Excel Discussion (Misc queries) | |||
Macro to copy sheets from several files into a new workbook. | Excel Programming |