Link to home
Create AccountLog in
Avatar of ilrosebud26
ilrosebud26Flag for United States of America

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.
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ilrosebud26

ASKER

Peetm-
    Thanks, I will try this after lunch and let you know.

Rosemary
That worked great!

Thanks!
Rosemary

Thanks for getting back so quickly.