Hi Folks,
I'm hoping someone can help me here, I have the code below that organises tif images into folders, however the problem is that when it's running there is no indicator as to how far along it has got with the process, which causes people to think that it isn't doing anything and has crashed. I would be most grateful if someone could help me put something within this code to show it's progress as it creates and put the tif images into their respective created folders. Here's the Code:
=========
BEGIN CODE
=========
Public Function OrganiseImages()
'This process identifies tif images in the specified path
'groups them together according to their Manufacturer, Batch
'Number and Date into their respective folders and sub folders
Dim FSO As FileSystemObject 'Declare the File System Object
Dim Folder As Folder 'Declare the folder object
Dim SubFolder As Folder 'Declare the sub folder object
Dim File As File 'Declare the File object
Dim SortDate 'Declare the SortDate variable
Dim SortBatch 'Declare the SortBatch variable
Dim ImagePath 'Declare the ImagePath variable
'Set the image path here
ImagePath = "\\prdfs01\images\"
'Set the FSO to new file system object
Set FSO = New FileSystemObject
'If the images folder can't be read, stop running
If Not FSO.FolderExists(ImagePath) Then
'Msgbox to state the folder doesn't exist
MsgBox "Folder Doesn't Exist"
End
End If
'Set the folder object to get the folder and open it
Set Folder = FSO.GetFolder(ImagePath)
'Read each file in images folder
For Each File In Folder.Files
' If file is a tif file then move it
If Right(File.Name, 4) = ".tif" Then
'Assign the date created to the SortDate variable in yyyymmdd format
'1st Mid - Get the year the file was created
'2nd Mid - Get the Month the file was created
'3rd Mid - Get the day the file was created
'Attached the left slash [\] at the end
SortDate = Mid(File.DateCreated, 7, 4) & Mid(File.DateCreated, 4, 2) & Mid(File.DateCreated, 1, 2) & "\"
'Batch destination folder name
SortBatch = Left(File.Name, InStrRev(File.Name, "_") - 1) & "\"
'If the date folder doesn't exist, create it
If Not FSO.FolderExists(ImagePath & SortDate) Then
FSO.CreateFolder (ImagePath & SortDate)
End If
'If the batch folder doesn't exist, create it
If Not FSO.FolderExists(ImagePath & SortDate & SortBatch) Then
FSO.CreateFolder (ImagePath & SortDate & SortBatch)
End If
'Move the file to the folder
File.Move (ImagePath & SortDate & SortBatch)
End If
DoEvents
Next
End Function
=========
END CODE
=========
Cheers
John
I'm hoping someone can help me here, I have the code below that organises tif images into folders, however the problem is that when it's running there is no indicator as to how far along it has got with the process, which causes people to think that it isn't doing anything and has crashed. I would be most grateful if someone could help me put something within this code to show it's progress as it creates and put the tif images into their respective created folders. Here's the Code:
=========
BEGIN CODE
=========
Public Function OrganiseImages()
'This process identifies tif images in the specified path
'groups them together according to their Manufacturer, Batch
'Number and Date into their respective folders and sub folders
Dim FSO As FileSystemObject 'Declare the File System Object
Dim Folder As Folder 'Declare the folder object
Dim SubFolder As Folder 'Declare the sub folder object
Dim File As File 'Declare the File object
Dim SortDate 'Declare the SortDate variable
Dim SortBatch 'Declare the SortBatch variable
Dim ImagePath 'Declare the ImagePath variable
'Set the image path here
ImagePath = "\\prdfs01\images\"
'Set the FSO to new file system object
Set FSO = New FileSystemObject
'If the images folder can't be read, stop running
If Not FSO.FolderExists(ImagePath) Then
'Msgbox to state the folder doesn't exist
MsgBox "Folder Doesn't Exist"
End
End If
'Set the folder object to get the folder and open it
Set Folder = FSO.GetFolder(ImagePath)
'Read each file in images folder
For Each File In Folder.Files
' If file is a tif file then move it
If Right(File.Name, 4) = ".tif" Then
'Assign the date created to the SortDate variable in yyyymmdd format
'1st Mid - Get the year the file was created
'2nd Mid - Get the Month the file was created
'3rd Mid - Get the day the file was created
'Attached the left slash [\] at the end
SortDate = Mid(File.DateCreated, 7, 4) & Mid(File.DateCreated, 4, 2) & Mid(File.DateCreated, 1, 2) & "\"
'Batch destination folder name
SortBatch = Left(File.Name, InStrRev(File.Name, "_") - 1) & "\"
'If the date folder doesn't exist, create it
If Not FSO.FolderExists(ImagePath & SortDate) Then
FSO.CreateFolder (ImagePath & SortDate)
End If
'If the batch folder doesn't exist, create it
If Not FSO.FolderExists(ImagePath & SortDate & SortBatch) Then
FSO.CreateFolder (ImagePath & SortDate & SortBatch)
End If
'Move the file to the folder
File.Move (ImagePath & SortDate & SortBatch)
End If
DoEvents
Next
End Function
=========
END CODE
=========
Cheers
John