If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Rename Excel file via VBA
You don't need that code. Use the name function to rename the file.
Name "c:\data\_ABC_123.xls" As "c:\data\ABC_123.xls" Chris Microsoft MVP wrote: 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 -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200810/1 |
#4
|
|||
|
|||
Rename Excel file via VBA
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 -- ~Your Friend Chris http://myvbastuff.blogspot.com/ thinking out loud " 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 |
Thread Tools | |
Display Modes | |
|
|