Results 1 to 9 of 9

renaming files with macro

Threaded View

  1. #3
    Registered User
    Join Date
    04-28-2009
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: renaming files with macro

    Quote Originally Posted by ravishankar View Post
    Hi
    Save the file in the folder where you want to rename the files. Run the macro by clicking the button on sheet1. Test it on a sample 3-4 files in a folder before using it. Col A will list current files. col B will list files with new names.
    Hope that helps
    Ravi
    Hello Ravi -

    I am interested in the macro you created. I have a similar task, where I need to name name images files. Where Column A will have the existing filename, and Column B will have the new file name.

    I am looking at your macro and am wondering if I change the following lines if it will work (Sorry for my noob-ness I have never done anything with VBA before). I deleted two lines and changed the line in BOLD

    So if I have a directory full of images:
    1.jpg
    2.jpg
    3.jpg
    4.jpg

    and my excel as the following (note it may not contain everything in the dir):
    | Column A | Column B |
    1.jpg | aa1.jpg
    3.jpg | cc3.jpg
    4.jpg | dd4.jpg


    Sub kaffal()
    Dim z As Long, e As Long, g As Long
    Dim f As String, b As String
    Sheets("Sheet1").Select
    Cells(1, 1) = "=cell(""filename"")"
    Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
    Cells(2, 1).Select
    f = Dir(Cells(1, 2) & "*.xls")
    Do While Len(f) > 0
    ActiveCell.Formula = f
    ActiveCell.Offset(1, 0).Select
    f = Dir()
    Loop
    z = Cells(Rows.Count, 1).End(xlUp).Row
    For e = 2 To z
    If Cells(e, 1) <> ActiveWorkbook.Name Then
    b = Cells(1, 2)
    Name Cells(1, 2) & Cells(e, 1) As b
    Cells(e, 2) = b
    End If
    Next e
    MsgBox "Renaming is complete."
    End Sub
    Last edited by judoGTI; 04-28-2009 at 04:38 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1