Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Dragon
 
Posts: n/a
Default Rename Excel Worksheet

Hi,

I have 4 Excel files that are created on a regular basis. Each file has one
worksheet. I need to find an automated method (VB Script?) that will simply
rename the worksheets within the files to the name of the file. For Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.


  #2   Report Post  
Ato Bisda
 
Posts: n/a
Default

Hello,

The code below should do the job assuming you have Excel installed:
--------------------------------------------------------------------
yourXlsFile = "c:\yourFolder\yourFile.xls"

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(yourXlsFile)
xlBook.Worksheets(1).Name = xlBook.Name
xlBook.Close 1
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
--------------------------------------------------------------------
Regards,
Ato

"Dragon" wrote in message ...
Hi,

I have 4 Excel files that are created on a regular basis. Each file has one
worksheet. I need to find an automated method (VB Script?) that will simply
rename the worksheets within the files to the name of the file. For Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.




  #3   Report Post  
tjtjjtjt
 
Posts: n/a
Default

Sub NameSheet()
ActiveSheet.Name = ActiveWorkbook.Name
End Sub
--
tj


"Dragon" wrote:

Hi,

I have 4 Excel files that are created on a regular basis. Each file has one
worksheet. I need to find an automated method (VB Script?) that will simply
rename the worksheets within the files to the name of the file. For Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.



  #4   Report Post  
JMB
 
Posts: n/a
Default

I don't know if this is exactly what you are looking for (as it is not
outside Excel), but one possibility is you could put two event handlers in
the Thisworkbook modules of your workbooks to change the sheet name whenever
the WB is opened or closed.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Sheets(1).Name < ThisWorkbook.Name Then
ThisWorkbook.Sheets(1).Name = ThisWorkbook.Name
ThisWorkbook.Save
End If
End Sub

Private Sub Workbook_Open()
If ThisWorkbook.Sheets(1).Name < ThisWorkbook.Name Then _
ThisWorkbook.Sheets(1).Name = ThisWorkbook.Name
End Sub


"Dragon" wrote:

Hi,

I have 4 Excel files that are created on a regular basis. Each file has one
worksheet. I need to find an automated method (VB Script?) that will simply
rename the worksheets within the files to the name of the file. For Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.



  #5   Report Post  
Dragon
 
Posts: n/a
Default

Thank you Ato. Works perfect. :-)


"Ato Bisda" wrote in message
...
Hello,

The code below should do the job assuming you have Excel installed:
--------------------------------------------------------------------
yourXlsFile = "c:\yourFolder\yourFile.xls"

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(yourXlsFile)
xlBook.Worksheets(1).Name = xlBook.Name
xlBook.Close 1
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
--------------------------------------------------------------------
Regards,
Ato

"Dragon" wrote in message
...
Hi,

I have 4 Excel files that are created on a regular basis. Each file has
one
worksheet. I need to find an automated method (VB Script?) that will
simply
rename the worksheets within the files to the name of the file. For
Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.








  #6   Report Post  
Dragon
 
Posts: n/a
Default

Thank you TJ for the reply.
I believe the script you mentioned works only within Excel and I needed a
script that I could use outside Excel.

"tjtjjtjt" wrote in message
...
Sub NameSheet()
ActiveSheet.Name = ActiveWorkbook.Name
End Sub
--
tj


"Dragon" wrote:

Hi,

I have 4 Excel files that are created on a regular basis. Each file has
one
worksheet. I need to find an automated method (VB Script?) that will
simply
rename the worksheets within the files to the name of the file. For
Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.





  #7   Report Post  
Dragon
 
Posts: n/a
Default

Thank you JMB.

I do not believe it will work in my situation as workbooks are created
automatically via a third party application that overwrites existing books
and will kill my in-file code. Also, another applications reads these files
so I am not sure if it actually opens it to ready or just reads it via code.

Thanks.

"JMB" wrote in message
...
I don't know if this is exactly what you are looking for (as it is not
outside Excel), but one possibility is you could put two event handlers in
the Thisworkbook modules of your workbooks to change the sheet name
whenever
the WB is opened or closed.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ThisWorkbook.Sheets(1).Name < ThisWorkbook.Name Then
ThisWorkbook.Sheets(1).Name = ThisWorkbook.Name
ThisWorkbook.Save
End If
End Sub

Private Sub Workbook_Open()
If ThisWorkbook.Sheets(1).Name < ThisWorkbook.Name Then _
ThisWorkbook.Sheets(1).Name = ThisWorkbook.Name
End Sub


"Dragon" wrote:

Hi,

I have 4 Excel files that are created on a regular basis. Each file has
one
worksheet. I need to find an automated method (VB Script?) that will
simply
rename the worksheets within the files to the name of the file. For
Example,
if I have a File1.xls with Sheet1 in it, script will simply rename the
Sheet1 to File1 or File1.xls. I need to do this to all my 4 files on a
regular basis so I will simply schedule this script. I need this method
outside excel so that it is portable. If I need to have either Excel or
Excel viewer, it is ok as well.

Thank you.





Reply
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
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
Change position of move or copy worksheet option in Excel JesseAviles Excel Discussion (Misc queries) 1 February 22nd 05 10:25 PM
Difference in number of Excel NewsGroups Hari Prasadh Excel Discussion (Misc queries) 1 January 25th 05 11:32 AM
Weekly Transaction Processing Ralph Howarth Excel Worksheet Functions 4 January 19th 05 05:37 AM
How do I replace a worksheet with another worksheet in excel Ammnon Excel Worksheet Functions 1 January 12th 05 10:48 AM


All times are GMT +1. The time now is 06:53 AM.

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"