ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Rename Excel file via VBA (https://www.excelbanter.com/excel-programming/419101-rename-excel-file-via-vba.html)

[email protected]

Rename Excel file via VBA
 
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

John Spencer

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



All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com