+ Reply to Thread
Results 1 to 3 of 3

macro to change the names and delete closed books

  1. #1
    Tim
    Guest

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


  2. #2
    Dave Peterson
    Guest

    Re: macro to change the names and delete closed books

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


    --

    Dave Peterson

  3. #3
    Tim
    Guest

    I figured it out


    I figured it out.
    Thak you for you answer Dave

+ 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