Rename File

  • Thread starter Thread starter craig
  • Start date Start date
C

craig

Is there a way to use VBA to rename a file in a folder? I currently export
3 files and use a batch file to combine the 3 files into one (header record,
detail record, footer record - all with different file lengths). I need to
rename the copied file with the format ccyyyymmddhhnn.csv. I create the
ccyyyymmddhhnn in a field on my form prior to exporting, but is there an API
or a VBA command I can use to rename this file AFTER I run my batch file to
combine? Is there a better way to do this?

TIA

Craig
 
You could use the filesystemobject and call the sub with
Renameit "yournewname.csv":

Sub RenameIt (NewNm as string )
Dim fs
Dim A
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.GetFile("c:\myfile.txt") 'this would be the old name
A.Name = NewNm
End Sub
 
Is there a way to use VBA to rename a file in a folder? I currently export
3 files and use a batch file to combine the 3 files into one (header record,
detail record, footer record - all with different file lengths). I need to
rename the copied file with the format ccyyyymmddhhnn.csv. I create the
ccyyyymmddhhnn in a field on my form prior to exporting, but is there an API
or a VBA command I can use to rename this file AFTER I run my batch file to
combine? Is there a better way to do this?

TIA

Craig

Yes: see the VBA help for the Name command.
 
Thanks Damon!

Damon Heron said:
You could use the filesystemobject and call the sub with
Renameit "yournewname.csv":

Sub RenameIt (NewNm as string )
Dim fs
Dim A
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.GetFile("c:\myfile.txt") 'this would be the old name
A.Name = NewNm
End Sub
 
Back
Top