Thread: Rename Tab
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Rename Tab

and with multiple workbooks open

Dim wBook As Workbook
Dim wSheet As Worksheet
Set wBook = Workbooks("<Workbookname")
Set wSheet = wBook.Sheets("Timesheet")

wSheet.Copy after:=wSheet
wBook.Sheets(wSheet.Index + 1).Name = wSheet.Cells(81, 1).Value
wSheet.PrintOut Copies:=1


If this post helps click Yes
---------------
Jacob Skaria


"Robert McCurdy" wrote:

Your code should resemble something like this Kerry.

Dim wks as worksheet
set wks = Sheets("Timesheet")

wks.PrintOut Copies:=1
wks.copy after:=wks
Sheets(wks.Index + 1).Name = wks.cells(81, 1).value

This avoids selecting or assuming the activesheet is really the one you want
the code to run on.
You might also consider if there is a valid sheet name in A81, and a cell 81
rows down is not a good place to have it, or see if it is correct. Sheet
name checking also requires no other sheet is named the same, so you can't
run this twice without an 1004 error.
Lastly if you are coping sheets, remember cells with more than 255
characters will be truncated.


Regards
Robert McCurdy
"Kerry" wrote in message
...
Hi Everyone,
By pressing one button I am trying to print out the timesheet, copy and
save
as a new sheet and then rename the tab from the formula in cell A81. It is
hanging at ActiveSheet.Name = Range("A81").Value. Any suggestions would
be
appreciated.

Sheets("Timesheet").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveSheet.Copy after:=ActiveSheet
ActiveSheet.Name = Range("A81").Value
Sheets("Timesheet").Select
--
Kerry