Re: Macro to copy files
- From: "Ron de Bruin" <rondebruin@xxxxxxxxxxxx>
- Date: Thu, 9 Nov 2006 16:59:37 +0100
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" <petersod@xxxxxxxxxxxxxxxx> wrote in message news:45532D9C.71D39B86@xxxxxxxxxxxxxxxxxxx
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" <DaveShaw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:E0AFFD5E-C117-451F-9530-C2950842A833@xxxxxxxxxxxxxxxx
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" <rondebruin@xxxxxxxxxxxx> wrote in message news:OGru5SoAHHA.4680@xxxxxxxxxxxxxxxxxxxxxxx
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" <DaveShaw@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3C31805F-28E0-487E-B550-2C056FC8E1B3@xxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- Re: Macro to copy files
- From: Ron de Bruin
- Re: Macro to copy files
- References:
- Re: Macro to copy files
- From: Ron de Bruin
- Re: Macro to copy files
- From: Ron de Bruin
- Re: Macro to copy files
- From: Dave Shaw
- Re: Macro to copy files
- From: Ron de Bruin
- Re: Macro to copy files
- From: Dave Shaw
- Re: Macro to copy files
- From: Dave Peterson
- Re: Macro to copy files
- Prev by Date: Re: Copy and PasteSpecial help
- Next by Date: How can I detect "nothing"?
- Previous by thread: Re: Macro to copy files
- Next by thread: Re: Macro to copy files
- Index(es):
Relevant Pages
|