A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Rename Excel file via VBA



 
 
Thread Tools Display Modes
  #1  
Old October 27th, 2008, 06:42 PM posted to microsoft.public.excel.programming,microsoft.public.access
[email protected]
external usenet poster
 
Posts: 28
Default 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
  #4  
Old October 27th, 2008, 07:06 PM posted to microsoft.public.excel.programming,microsoft.public.access
vbasean
external usenet poster
 
Posts: 113
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.