I would like scan if a folder (IMAGES) exits with image(jpg) files in it. If there are image files in that folder, then it must count the number of images and copy to a destination folder with success message . If there are no files in the folder then a message with "NO Images Found" must display.
Any help would be appreciated.
I tried below code, but it allows to select the source folder and it copies if there are images. But if there are no images, it gives ERROR. Also there is no count of images.
Sub CopyImages()
Dim FSO As Object
Dim Path As String
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
ChDrive "D:"
ChDir "D:\SOURCE\HTML"
Path = Application.FileDialog(msoFileDialogFolderPicker).Show
FromPath = Application.FileDialog( _
msoFileDialogOpen).SelectedItems(1)
ToPath = "D:\SOURCE\SCAN" '<< Change
FileExt = "*.jpg" '<< Change
'You can use *.* for all files or *.doc for word files
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " Images doesn't exist"
Exit Sub
End If
If FSO.FolderExists(ToPath) = False Then
MsgBox ToPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "Image Files Copied Successfully"
End Sub