Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to copy files

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Macro to copy files

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
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
Macro to copy and paste over existing files Cam Excel Discussion (Misc queries) 1 July 1st 09 08:37 PM
Macro 4 copy & paste between 2 books/files FARAZ QURESHI Excel Discussion (Misc queries) 1 October 7th 07 06:41 PM
Macro to create a folder and copy files GainesvilleWes New Users to Excel 2 February 26th 07 06:33 PM
using macro, how can i copy similar fields from other xls files? Shaji Valiath Excel Discussion (Misc queries) 1 May 23rd 06 10:08 AM
Macro to copy sheets from several files into a new workbook. [email protected] Excel Programming 2 November 10th 05 10:45 PM


All times are GMT +1. The time now is 06:37 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"