Results 1 to 2 of 2

Changing all excel workbook names in a folder code is not working

Threaded View

salventuro Changing all excel workbook... 05-08-2009, 06:59 PM
salventuro Re: Changing all excel... 05-08-2009, 11:41 PM
  1. #1
    Registered User
    Join Date
    04-11-2009
    Location
    Toronro
    MS-Off Ver
    Excel 2003
    Posts
    15

    Changing all excel workbook names in a folder code is not working

    Hello everyone,

    Hope everyone is having a great day!

    I am having trouble getting this code to loop though a folder.

    ActiveWorkbook.SaveAs Filename:=Cells(4, 6).Value & Cells(4, 7).Value & Cells(4, 8).Value
    I am trying to rename all the excel workbooks in a folder, to corresponding cells in each workbook, the workbooks should be renamed using the values of the selected cells as follows,

    F4G4H4
    F4 is a proper name, G4 is a set of four numbers and F4 is also a set of four numbers. There aren't any illegal charaters in the cells I have selected.

    The excel workbooks (will be 100's at a time) in the folder.
    I have had success with the "loop" code with 3 other codes, this one gives me the 'A file named (me98981212, as an example) already exists in this location. Do you want to replace it? message box.

    I can see the selected workbook open and the name of the file, in the title bar change. But, when I select Yes to the changes, the name of the excel file reverts back to the original name.

    I don't need the message box to appear to confirm the change either.

    Could someone provide some insight to this?

    I hope I have provided enough information, to make the issue clear.

    Here is the final code I am using.



    Option Explicit
    
    Sub Exec_Macro_For_All()
    
    Dim sPath As String
    Dim sFile As String
    Dim sDir As String
    Dim oWB As Workbook
    Dim i1 As Long
    Dim iMax As Long
    
    On Error GoTo Err_Clk
    
    sPath = "D:\loop test"
    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
    
    sDir = Dir$(sPath & "*.xls", vbNormal)
    Do Until LenB(sDir) = 0
    Set oWB = Workbooks.Open(sPath & sDir)
    
    ActiveWorkbook.SaveAs Filename:=Cells(4, 6).Value & Cells(4, 7).Value & Cells(4, 8).Value
    
    Application.ScreenUpdating = False
    
    oWB.Save
    oWB.Close False
    sDir = Dir$
    Loop
    
    Err_Clk:
    If Err <> 0 Then
    Err.Clear
    Resume Next
    End If
    End Sub
    My Thanks in advance.
    Last edited by salventuro; 05-08-2009 at 11:41 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