Results 1 to 3 of 3

Using 'Name ..... As .....' with a wildcard

Threaded View

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2010
    Posts
    25

    Using 'Name ..... As .....' with a wildcard

    Trying to write part of a macro to rename a file held in a specific directory. Each day the directory will hold a different file with a different file name however the first several characters will always be the same.

    The directory is C:\Report Files\Daily File\ and the file always starts with same characters - 'PCDAILY' (file name is normally something like 'PCDAILY03082012' or 'PCDAILY26072012')

    My aim is to rename the file so it's always called 'PCDAILY' (getting rid of all the superfluous numbers) so I can use that name reference throughout the rest of the macro. I am trying to use a wildcard in conjunction with the 'Name' statement to alter the name but cannot get it to work.

    Sub renamer()
    
    Dim FileLocation As String
    Dim OldName As String
    Dim NewName As String
    
    FileLocation = "C:\Report Files\Daily File\"
    OldName = Left(FileLocation,7) = "PCDAILY"
    NewName = "PCDAILY.csv"
    
    Name FileLocation & OldName As FileLocation & NewName
    
    End Sub
    Would greatly appreciate any suggestions.

    Thanks,

    Daniel.
    Last edited by Iwasiw35; 08-05-2012 at 09:44 PM.

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