macro to change the names and delete closed books

T

Tim

Hi,

In a folder located in C:\Documents and Settings\Tim\My
Documents I have a number of workbooks and I need to
create a code which will change the names of the
workbooks automatically.
To be more specific the names of the workbooks are:
1,2,3,4 and 5, and the code should change the names like
this: book "5" becomes 4, 4 becomes 3, 3 becomes 2, and
the name of book "2" becomes 1, book 1-delete.
Any help is highly appreciated.
 
D

Dave Peterson

how about:

Option Explicit
Sub testme()
Dim myFolder As String
Dim iCtr As Long

myFolder = "C:\Documents and Settings\Tim\My Documents"

If Right(myFolder, 1) <> "\" Then
myFolder = myFolder & "\"
End If

On Error Resume Next 'in case the name isn't there
Kill myFolder & "delete.xls"
Name myFolder & "1.xls" As myFolder & "delete.xls"

For iCtr = 2 To 4
Name myFolder & iCtr & ".xls" As myFolder & iCtr - 1 & ".xls"
Next iCtr
On Error GoTo 0

End Sub
 
Top