Excel File Rename Macro Help!

P

philip260

Hello All!

Daily csv files are dumped into a shared folder and i have written a
macro that goes into that folder and automatically pull in data to put
it in microsoft access tables. What i want to do next is after
importing the data into access, rename those files to include dates and
times. This import runs every morning so whenever a new csv is dumped
in there, my macro will run the newest ones and avoid the past ones.
Any ideas guys? I guess im looking for a rename macro sql script.
Please see below script. Any help would be greatly appreciated!!



Dim fso As Object, fol As Object, fils As Object, f As Object
Dim strPathFile As String, strFile As String, strPath As String,
strSpec As String
Dim strTable As String, ynFieldName As Boolean


' use ynFieldName to tell TransferText whether .csv file has
field names (True) Or Not (False)

ynFieldName = False

' strPath is the path to the folder in which the files will be
placed
strPath = "C:\Documents and Settings\seipxz\Desktop\BI - JP\"

' strSpec is name of import specification
strSpec = "specCSVImport"

'strTable is name of table to which file is to be imported
strTable = "specCSVImport"


Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder(strPath)
Set fils = fol.Files
For Each f In fils ' checks all files in the folder
specified above

If Right(f.Name, 22) = "AppndComplResearch.csv" Then '
found a ".csv" file
strPathFile = strPath & f.Name ' set entire
path&file name
' import .csv file
DoCmd.TransferText acImportDelim, strSpec, strTable,
strPathFile, ynFieldName
' delete the file that was just imported (leave out
this step if you want to manually delete the file)
'f.delete

End If

Next f
 
D

Don Guillett

maybe this simple idea will help?
Sub movefile()
OldName = "C:\oldfolder\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
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

Top