?
Solved

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

Posted on 2013-01-14
3
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

762 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