ilrosebud26
asked on
Check for file during archive - vb from excel
I have a macro which copies files from one directory to another only if the following condition exists:
Costs*.xls. If there are no files in the source directory, the vb script produces an error message that I do not want the users to see. Is there any way to display a message box that says there are no files that meet the archive criterion? I have attached my macro for your review.
Costs*.xls. If there are no files in the source directory, the vb script produces an error message that I do not want the users to see. Is there any way to display a message box that says there are no files that meet the archive criterion? I have attached my macro for your review.
Sub ArchiveFiles()
Dim fso As Object
Dim sSourceDir As String
Dim sTargetDir As String
sSourceDir = "C:\my documents\"
sTargetDir = "C:\my documents\backup\"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.movefile Source:=sSourceDir & "Costs*.xls", Destination:=sTargetDir
fso.movefile Source:=sSourceDir & "Status*.xls", Destination:=sTargetDir
End Sub
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
That worked great!
Thanks!
Rosemary
Thanks!
Rosemary
ASKER
Thanks for getting back so quickly.
ASKER
Thanks, I will try this after lunch and let you know.
Rosemary