|
-
August 4th, 2009, 05:16 AM
#4
Re: Renaming Pictures files by comparing a list
Hi dglienna
thanks for the reply. I think a bit overkill for what I need. All I need to be able to do is compare the filename with values in Column A in the spreadsheet. If it exists in that column then rename the File with the contents of the Value in column B.
I have managed to write this in VBA in the spreadsheet:
Code:
Option Explicit
Sub RenameFiles()
Dim lngRow As Long, lngRowCount As Long, lngStartRow As Long
Dim vPath, vFile As String
On Error Resume Next
lngRowCount = Cells(1325, "A").End(xlUp).Row
lngStartRow = 1
Application.ScreenUpdating = False
vPath = "C:\Photos\" '' new
vFile = Dir(vPath & "*.jpg") '' new
Do While vFile <> "" '' new
For lngRow = lngStartRow To lngRowCount
'If Len(Cells(lngRow, "E").Value) > 0 And Len(Cells(lngRow, "B").Value) > 0 Then
If vFile = Cells(lngRow, "E").Value & ".jpg" Then
Name vPath & vFile As vPath & Cells(lngRow, "B").Value & ".jpg" '' new
vFile = Dir '' new
'Name strPath & Cells(lngRow, "E").Value As strPath & Cells(lngRow, "B").Value
Cells(lngRow, "F").Value = "Renamed"
Else
Cells(lngRow, "F").Value = "Not Renamed"
End If
'End If
Next lngRow
Loop '' new
Application.ScreenUpdating = True
End Sub
It renames the files, but they aren't in the correct order. The files are pics of students in the school I work in and the filenames are their student id. A new attendance system has created new Student IDs for them - hence the need to rename them to the new IDs.
Any ideas?
Last edited by brjames32; August 4th, 2009 at 05:18 AM.
Visual Basic 2005 ver. 8.0.50727.867
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|