ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro to change the names and delete closed books (https://www.excelbanter.com/excel-discussion-misc-queries/11692-macro-change-names-delete-closed-books.html)

Tim

macro to change the names and delete closed books
 
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 a
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.


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

Tim wrote:

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 a
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.


--

Dave Peterson

Tim


I figured it out.
Thak you for you answer Dave


All times are GMT +1. The time now is 11:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com