View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.access
John Spencer John Spencer is offline
external usenet poster
 
Posts: 1
Default Rename Excel file via VBA


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

wrote:
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