+ Reply to Thread
Results 1 to 17 of 17

Changing File Names in Excel Folder

Hybrid View

  1. #1
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Changing File Names in Excel Folder

    JPDutch,

    Something like this?
    Sub tgr()
        
        Const strFldrPath As String = "H:\SAFETY\FORMS\ 300 & 300A\2011\"
        Dim strFile As String: strFile = Dir(strFldrPath)
        
        While strFile <> vbNullString
            Name strFldrPath & strFile As Replace(strFldrPath & strFile, "2010", "2011")
            strFile = Dir
        Wend
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing File Names in Excel Folder

     
    Sub snb()
     For Each fl In CreateObject("scripting.filesystemobject").getfolder("H:\SAFETY\FORMS\ 300 & 300A\2011").Files
      fl.Name = Replace(fl.Name, "_2010", "_2011")
     Next
    End Sub



  3. #3
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Changing File Names in Excel Folder

    snb: Thanks for your help. This worked on the first four files and the last one, and then I got an error message: "Run-time error '58': File already exists. When I click on debug it highlights: fl.Name = Replace(fl.Name, "_2010", "_2011"). Is there something I need to correct? JPDutch

  4. #4
    Registered User
    Join Date
    01-15-2011
    Location
    Clearfield, UT
    MS-Off Ver
    Excel 2016
    Posts
    58

    Re: Changing File Names in Excel Folder

    Tigeravatar: thanks for your help. I tried this out, but nothing happened. Any suggestions? JPDutch

+ 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