Solved

rename in batch ,many photos in a dir , from a xls list column data ?

Posted on 2013-01-14
3
267 Views
Last Modified: 2013-01-14
i have a dir   "Photos_ID1"  in desktop , with photos named  all ready from a list of column ''B''  in sheet  "Prod_Photos" also there is a photo called "No_photo_yet.jpg"


   " A "                                         " B "          Dir  "Photos_ID1"      final result on dir
Su10000-M95-C413               156-0099          156-0099.jpg          Su10000-M95-C413.jpg
Su10001-M520-C41           140-1829          140-1829.jpg         Su10001-M520-C41.jpg                
Su10002-M95-C413               156-0145           156-0145.jpg       Su10002-M95-C413.jpg

1.         i want to compare the "B"  list with dir /photos and if i dont have photo with the selected value ,  i want  in  "B" column  to replace the cell  with value "No_photo_yet"

2nd ....i want to rename  the photos in dir ,with the "A" column

Do this for 6000 values in "B" or "A"
   

many thanks , to everyone that helps.
0
Comment
Question by:tonyantony
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 250 total points
ID: 38774116
with values listed in A & B (nothing in Columns C and D)...

Save the attached file in the "Photos_ID1" folder and run the following macro...

Sub Change_JPEG()

strPath = ThisWorkbook.Path
Dim xx As String
Dim arr

LastDataRow = Cells(Rows.Count, 1).End(xlUp).Row

arr = Range("A1:D" & LastDataRow).Value

For x = 1 To UBound(arr)
If Len(Dir(strPath & "\" & arr(x, 2) & ".jpg")) <> 0 Then
    Name strPath & "\" & arr(x, 2) & ".jpg" As strPath & "\" & arr(x, 1) & ".jpg"
    arr(x, 3) = strPath & "\" & arr(x, 2) & ".jpg"
    arr(x, 4) = strPath & "\" & arr(x, 1) & ".jpg"
Else
    arr(x, 3) = "No_photo_yet"
    arr(x, 4) = ""
End If
Next x
Range("A1:D" & LastDataRow).Value = arr

End Sub

Open in new window


Option 2 columns:
Sub Change_JPEG()

strPath = ThisWorkbook.Path
Dim xx As String
Dim arr

LastDataRow = Cells(Rows.Count, 1).End(xlUp).Row

arr = Range("A1:B" & LastDataRow).Value

For x = 1 To UBound(arr)
If Len(Dir(strPath & "\" & arr(x, 2) & ".jpg")) <> 0 Then
    Name strPath & "\" & arr(x, 2) & ".jpg" As strPath & "\" & arr(x, 1) & ".jpg"
Else
    arr(x, 2) = "No_photo_yet"
End If
Next x
Range("A1:B" & LastDataRow).Value = arr
End Sub

Open in new window

Dir-change.xlsm
Dir-change.xlsm
0
 

Author Closing Comment

by:tonyantony
ID: 38775738
i tested 1st macro ,  no need for the other, works fine many thanks , good job
0
 
LVL 24

Expert Comment

by:Steve
ID: 38775758
Glad to help, I just did the second as it was what you asked for, but I thought leaving the original data alone was a cleaner result.

ATB
Steve.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associateā€¦
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns overā€¦
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question