+ Reply to Thread
Results 1 to 2 of 2

How do you rename Multiple files using text from a cell in the file?

  1. #1
    RandyR
    Guest

    How do you rename Multiple files using text from a cell in the file?

    I could use some help writing my macro for excel. This is what I have:

    1) I have 3 files in C:/sample named 1.xls, 2.xls, and 3.xls (this
    varies from 2 - 30 files)
    2) I need to save each one using text in cell E28

    I would like:

    1) An input prompt when Macro starts to ask how many files.
    2) Then the Macro to run through all numbered files saving the file
    using what text is in cell E28 as the new file name.

    I have been able to get it to do the first file, but I can't get the
    variable to change on the second and additional files.

    Thanks for your Help.


  2. #2
    Ron de Bruin
    Guest

    Re: How do you rename Multiple files using text from a cell in the file?

    Try this

    Select the files you want in the open dialog that popup (use the Ctrl key)

    It use E28 in the first sheet of each workbook
    mybook.SaveAs Sheets(1).Range("E28") & ".xls"

    Sub Example()
    Dim mybook As Workbook
    Dim N As Long
    Dim MyPath As String
    Dim SaveDriveDir As String
    Dim FName As Variant

    SaveDriveDir = CurDir
    MyPath = "C:\Data\"
    ChDrive MyPath
    ChDir MyPath

    FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", _
    MultiSelect:=True)
    If IsArray(FName) Then
    Application.ScreenUpdating = False

    For N = LBound(FName) To UBound(FName)
    Set mybook = Workbooks.Open(FName(N))
    mybook.SaveAs Sheets(1).Range("E28") & ".xls"
    mybook.Close False
    Next
    End If
    ChDrive SaveDriveDir
    ChDir SaveDriveDir
    Application.ScreenUpdating = True
    End Sub



    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "RandyR" <rrice@cainternationalinc.com> wrote in message news:1126894650.656376.182070@g47g2000cwa.googlegroups.com...
    >I could use some help writing my macro for excel. This is what I have:
    >
    > 1) I have 3 files in C:/sample named 1.xls, 2.xls, and 3.xls (this
    > varies from 2 - 30 files)
    > 2) I need to save each one using text in cell E28
    >
    > I would like:
    >
    > 1) An input prompt when Macro starts to ask how many files.
    > 2) Then the Macro to run through all numbered files saving the file
    > using what text is in cell E28 as the new file name.
    >
    > I have been able to get it to do the first file, but I can't get the
    > variable to change on the second and additional files.
    >
    > Thanks for your Help.
    >




+ Reply to Thread

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