Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Rename file within a directory using creating date

Hi,

Could someone please assist me with obtaining the correct code for renaming
a file or multiple files in a directory to include its creation date. This is
the code I have so far and thanks in advance for any assistance:

Sub RenameFileToDatedFile()

'Install a refernce to library: Microsoft Scripting Runtime

Dim FSO As New FileSystemObject
Dim afile As file 'Handle for fso 'File' Object
Dim aPath As String
Dim aName As String
Dim sNewFile As String
Dim sOldFile As String

'Set up your filespec
aPath = sfol = "C:\Temp\Reports\"
aName = "pcb.ppt"

If FSO.FileExists(aPath & aName) Then
Set afile = FSO.GetFile(aPath & aName) '<< Example of setting
handle
' MsgBox "The File exists " & aFile.DateCreated

'Range("B50") = aFile.DateCreated

sOldFile = "C:\Temp\Reports\pcb.ppt"
sNewFile = "C:\Temp\Reports\Final PCB Data " & Format(afile.DateCreated,
"dd-mmm-yy") & ".ppt"

Name sOldFile As sNewFile

End If

'Clean House
Set afile = Nothing

End Sub
--
By persisting in your path, though you forfeit the little, you gain the
great.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Rename file within a directory using creating date


You are 99.9% correct. You need one more statement

FSO.MoveFile sOldFile,sNewFile


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=150611

Microsoft Office Help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you copy a Excel file to a new directory and rename it? pokdbz Excel Discussion (Misc queries) 1 August 1st 07 08:44 PM
Rename file based on current date wira Excel Programming 1 April 29th 05 10:37 AM
Creating a macro that lists directory names within a directory.... Andy Excel Programming 4 November 28th 04 06:13 AM
Can I rename a directory using a macro Harvey[_3_] Excel Programming 2 February 6th 04 01:49 PM
Creating a directory from a date mark Excel Programming 1 July 17th 03 11:10 AM


All times are GMT +1. The time now is 03:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"