RENAME FILE USING FILESYSTEMOBJECT
Renaming a file and displaying Drive & File Information
Copy and paste the following code into a Standard Module in your Project.
Sub ShowFileAccessInfo() Dim fs, f, s On Error GoTo ShowFileAccessInfo_Err Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.Getfile("C:\mytext.txt") s = f.Name & " on Drive " & UCase(f.Drive) & vbCrLf 'renames the file named c:\mytext.txt as yourtext.txt f.Name = "yourtext.txt" s = s & "New Name: " & f.Name & vbCrLf s = s & "Created: " & f.DateCreated & vbCrLf s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf s = s & "Last Modified: " & f.DateLastModified MsgBox s, 0, "File Access Info" ShowFileAccessInfo_Exit: Exit Sub ShowFileAccessInfo_Err: MsgBox Err.Description, , "ShowFileAccessInfo" Resume ShowFileAccessInfo_Exit End Sub
Change the program lines wherever the sample text file reference: c:\mytext.txt is appearing in the code with one of your own text file pathname.
Next >> Display Path and File Info.