ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Naming File from a Cell (https://www.excelbanter.com/excel-programming/274025-naming-file-cell.html)

RisingStar

Naming File from a Cell
 
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



Orlando Magalhães Filho

Naming File from a Cell
 
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

---
Orlando Magalhães Filho

(So that you get best and rapid solution and all may benefit from the
discussion, please reply within the newsgroup, not in email)


"RisingStar" escreveu na mensagem
...
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






All times are GMT +1. The time now is 11:20 AM.

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