How to set up a worksheet name as file name

  • Thread starter Thread starter Sunil Pal
  • Start date Start date
S

Sunil Pal

I want worksheet name to be auto change when I change the file name
 
In the ThisWorkbook module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
ActiveSheet.Name = Me.Name 'refer to your sheet if it's not the active
sheet
End Sub

Sheet names are limited to 31 characters, so you may want to do
something like this:

If Len(Me.Name) > 31 Then ActiveSheet.Name = Left(Right(Me.Name,
35), 31)

Cliff Edwards
 

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

Back
Top