Naming File from a Cell

R

RisingStar

Is it possible to change the name of an excel worksheet and create a new
filename from one of the cells? The source cell is a name in format:
Surname, Firstname

Thanks for your help

MR
 
O

Orlando Magalhães Filho

Hi RisingStar,

Try this:
- Open your workbook;
- Right click on tab sheet;
- Click View Code command;
- Insert the code below;
- Now inserting a string on A1 cell the file name will be changed as.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim OldFileName As String
Dim NewFileName As String
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
NewFileName = Range("A1").Value
NewFileName = Replace(NewFileName, ", ", "_")
OldFileName = ThisWorkbook.FullName
ThisWorkbook.SaveAs ThisWorkbook.Path & "\" & NewFileName & ".xls"
Kill OldFileName
End Sub



HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top