Rename Excel file via VBA

L

lecoughlin

Hi All,
I have the following VBA code that opens an Excel file from my Access
database. Does anyone know how I would write the code to rename the
file? For example, rename "_ABC_123" to "ABC_123"

Thanks in advance!

Dim strInputFileName As String

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)",
"*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)


Dim db As DAO.Database
Dim myRec As DAO.Recordset

Set xlApp = CreateObject("Excel.Application")

Set xlApp = CreateObject("Excel.Application")
Set xlWrkBk = xlApp.Workbooks.Open(strInputFileName)
Set db = CurrentDb
 
J

John Spencer

Name oldpathname As newpathname

Name "c:\_ABC_123.xls" AS "c:\ABC_123.xls"

The file cannot be open when you rename it. If it is you will get an error.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
V

vbasean

Private Sub testrename(OldFilename as string, NewFilename as string)
'these are examples of how your sub routine might receive these variables
'oldname = "C:\yourpath\Old name.xls"
'newname = "C:\yourpath\New name.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