LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Renaming an Excel file using a macro

Assume the values are in sheet1, cells A1, B1, C1 in the order you describe

You can use the Beforeclose event

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error goto ErrHandler
application.EnableEvents = False
sPath = ThisWorkbook.Path
if Right(spath,1) < "\" then _
sPath = sPath & "\"
Application.DisplayAlerts = False
with thisWorkbook.Worksheets("Sheet1")
ThisWorkbook.SaveAs FileName:= sPath &
.Range("A1").value & "_" & .Range("B1").Value & _
"_" & .Range("C1").Value & ".xls"
End With
Application.DisplayAlerts = False
ErrHandler:
Application.EnableEvents = True
End Sub

This code would be placed in the ThisWorkbook Module. It forces a save of
the workbook which is not always desirable.

If you are not familiar with events, seee Chip Pearson's page on Events:

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy


"Sinex" wrote in message
...
Hi,
I made an Excel sheet (say Form.xls). There are 3 fields which a user
will fill (say First, Middle & Last Name). When the user closes the file,

I
want to rename the file to FirstName_MiddleName_LastName.xls (using the
values entered in the sheet). Is this possible using some

macro....renaming
a file while the file is still open sounds like an issue.

...manoj




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming an excel file that is Linked. dls25 Excel Worksheet Functions 6 April 28th 23 03:42 AM
Excel Renaming Files When Opening Using File Convertor William McCann Excel Discussion (Misc queries) 0 November 25th 09 03:41 PM
Renaming A File Rose Excel Discussion (Misc queries) 2 December 14th 06 05:33 PM
Excel renaming file to a temp and deletes original (long) John Excel Programming 1 June 16th 04 08:57 PM
Renaming a file Paul C[_2_] Excel Programming 1 January 23rd 04 04:13 PM


All times are GMT +1. The time now is 10:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"