Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 27th, 2007, 06:16 PM
Registered User
Join Date: Oct 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default excel rename and move files

VB script to select folder to open each excel file and then rename and save them into another folder then close each file. (files are read only templates that need updating)

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject

Dim strCurrentFolder
strCurrentFolder = "c:\source folder"
Dim objFolder
Set objFolder = objFSO.GetFolder (strCurrentFolder)

ListDirectory objFolder

Sub ListDirectory(objFolder)
  Dim objFile
  Dim objSubFolder

  For Each objFile In objFolder.Files
    If UCase(Right(objFile.Path, 3)) = "XLS" Then
        objFSO.MoveFile objFile.Path, strcurrentfolder & NewFileName
    End If
End Sub

this script moves and renames the files but I want to keep the original files. Trying to modify this script to do what posted at the top of this post though.

  #2 (permalink)  
Old October 28th, 2007, 09:27 PM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts

Try with

objFSO.CopyFile objFile.Path, strcurrentfolder & NewFileName



VBA Tips & Tricks (http://www.vbadud.blogspot.com)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure to move files gbminnock SQL Server 2000 1 November 23rd, 2007 07:44 AM
Rename VBProject in Excel 2007 chunchoazul Excel VBA 1 May 21st, 2007 12:41 AM
Files need to move different folder surendran PHP How-To 2 June 20th, 2006 10:27 PM
How to create a folder in server and rename files pramos.21d ASP.NET 2.0 Basics 0 April 24th, 2006 05:27 AM
Rename external files from within access timmaher Access VBA 1 March 24th, 2004 10:37 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.