Rename File

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
 
D

Damon Heron

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
 
J

John W. Vinson

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

craig

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top