pizdyetz77
07-18-2003, 12:31 PM
This is the code I'm using to copy all xls files in a folder to a new one and to then delete the ones in the original folder.
My problem is that there is one xls files in that original folder that I want to keep there.
Is this possible?
Absolute beginner here, so simple answers (other than yes or no) would be greatly appreciated.
Thanks
GH
Sub MoveMultiple()
Dim T As String
T = Dir("C:\Profit~1\Testin~1\*.xls") 'Specify Path and get first file
Do 'loop until all files read
If T <> "" Then 'Make sure a file has been found
FileCopy "C:\Profit~1\Testin~1\" & T, "C:\Profit~1\Movedt~1\" & T 'copy the file
End If
T = Dir 'Get the next file
Loop Until T = "" 'If there is no next file exit loop
Kill "C:\Profit~1\Testin~1\*.xls"
End Sub
Iceplug
07-18-2003, 12:35 PM
You have the If statement set up... all you need to do is check if it is the file that you don't want to move
If T <> "" And T <> "C:\x\y\notme.xls" Then
:)
pizdyetz77
07-18-2003, 01:01 PM
Thanks for the quick (and seemingly simple) reply. Just not simple enough for me it seems.
I put that in but it still moves the file "notme.xls"
Also, how would I stop that file being deleted along with all the other xls files? Obviously the kill statement is still deleting all the xls files
Here's what I did according to what you said:
Hope you can help again
GH
Sub MoveMultiple()
Dim T As String
T = Dir("C:\Profit~1\Testin~1\*.xls") 'Specify Path and get first file
Do 'loop until all files read
If T <> "" And T <> "C:\Profit~1\Testin~1\notme.xls" Then 'Make sure a file has been found
FileCopy "C:\Profit~1\Testin~1\" & T, "C:\Profit~1\Movedt~1\" & T 'copy the file
End If
T = Dir 'Get the next file
Loop Until T = "" 'If there is no next file exit loop
Kill "C:\Profit~1\Testin~1\*.xls"
End Sub
Iceplug
07-18-2003, 01:22 PM
Print out the results of T to the debug window and then substitute the one that you want to keep in place of what you added. :)
Debug.Print T
pizdyetz77
07-18-2003, 01:23 PM
This will seem really basic to all of you guys out there but this is how I worked around it. Not clever, I know, so if anyone can still come up with the 'proper' way to do it then I'd be grateful:
I basically renamed the file I don't want to move as a .doc and then afterwards rename back to being a .xls.
Sub MoveMultiple3()
Name "C:\Profit~1\Testin~1\notme.xls" As "C:\Profit~1\Testin~1\notme.doc"
Dim T As String
T = Dir("C:\Profit~1\Testin~1\*.xls") 'Specify Path and get first file
Do 'loop until all files read
If T <> "" Then 'Make sure a file has been found
FileCopy "C:\Profit~1\Testin~1\" & T, "C:\Profit~1\Movedt~1\" & T 'copy the file
End If
T = Dir 'Get the next file
Loop Until T = "" 'If there is no next file exit loop
Kill "C:\Profit~1\Testin~1\*.xls"
Name "C:\Profit~1\Testin~1\notme.doc" As "C:\Profit~1\Testin~1\notme.xls"
End Sub
Can anyone make me look a bit more knowledgeable?
Thanks
GH
pizdyetz77
07-18-2003, 01:26 PM
Iceplug,
I posted my reply just as your's came in. Unfortunately your's made no sense to me whatsoever. From my workaround you'll see how inexperienced I am - I speak English, Russian, French and German - this VB stuff makes little sense to me though. :)
Would you mind explaining that last bit to me again?
Thanks
GH
Iceplug
07-18-2003, 02:47 PM
Are you familiar with the Debug window?
[Debug.Print T] will print the contents of T into the immediate window... from there you can examine all the files that Dir$ has read.
Ctrl+G should show your Immediate window for you. :)