[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-01-14
3
Medium Priority
?
286 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

649 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