Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Renaming a copied sheet programatically

Hi.

I have an Excel spreadsheet with tabs named as Week Numbers. I'm using VBA
in MS Access to copy the previous week's sheet if one for the current week
doesn't exist. I can copy the sheet but it's given the name (for example)
"822 (2)". How do I select the new sheet in order to rename it "823"?
Here's the bit of code in question. Many thanks.

Keith.

If libSheetExists(objWkb, objSht, strWeekNo) = False Then
Dim strLastWeek As String
strLastWeek = strWeekNo - 1
Set objSht = objWkb.Worksheets(strLastWeek) 'Select the previous week's
sheet
objSht.Activate
objSht.Copy After:=Sheets(strLastWeek)
'HOW DO I SELECT THE NEW WORKSHEET?
objSht.Name = strWeekNo
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Renaming a copied sheet programatically

"Keith Wilby" wrote in message
...
How do I select the new sheet in order to rename it "823"?


Doesn't matter. This is how I've done it:

objSht.Copy After:=Sheets(strLastWeek)
strLastWeek = strLastWeek & " (2)"
Set objSht = objWkb.Worksheets(strLastWeek)
objSht.Name = strWeekNo

Is there a more elegant way?

Thanks.

Keith.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Renaming a copied sheet programatically

the new worksheet is automatically selected when it's copied

On 3 Cze, 15:27, "Keith Wilby" wrote:
Hi.

I have an Excel spreadsheet with tabs named as Week Numbers. *I'm using VBA
in MS Access to copy the previous week's sheet if one for the current week
doesn't exist. *I can copy the sheet but it's given the name (for example)
"822 (2)". *How do I select the new sheet in order to rename it "823"?
Here's the bit of code in question. *Many thanks.

Keith.

If libSheetExists(objWkb, objSht, strWeekNo) = False Then
* * Dim strLastWeek As String
* * strLastWeek = strWeekNo - 1
* * Set objSht = objWkb.Worksheets(strLastWeek) 'Select the previous week's
sheet
* * objSht.Activate
* * objSht.Copy After:=Sheets(strLastWeek)
* * 'HOW DO I SELECT THE NEW WORKSHEET?
* * objSht.Name = strWeekNo
End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Renaming a copied sheet programatically

...

ActiveSheet.Name= strWeekNo

HIH

On 3 Cze, 15:39, Jarek Kujawa wrote:
the new worksheet is automatically selected when it's copied

On 3 Cze, 15:27, "Keith Wilby" wrote:



Hi.


I have an Excel spreadsheet with tabs named as Week Numbers. *I'm using VBA
in MS Access to copy the previous week's sheet if one for the current week
doesn't exist. *I can copy the sheet but it's given the name (for example)
"822 (2)". *How do I select the new sheet in order to rename it "823"?
Here's the bit of code in question. *Many thanks.


Keith.


If libSheetExists(objWkb, objSht, strWeekNo) = False Then
* * Dim strLastWeek As String
* * strLastWeek = strWeekNo - 1
* * Set objSht = objWkb.Worksheets(strLastWeek) 'Select the previous week's
sheet
* * objSht.Activate
* * objSht.Copy After:=Sheets(strLastWeek)
* * 'HOW DO I SELECT THE NEW WORKSHEET?
* * objSht.Name = strWeekNo
End If- Ukryj cytowany tekst -


- Pokaż cytowany tekst -


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
copied formulas refer to destination sheet not source sheet Dantron Excel Worksheet Functions 2 October 21st 09 09:51 PM
renaming copied worksheets deleting .xls] dhl Excel Worksheet Functions 2 July 11th 05 10:55 PM
Setting sheet.xlt for a workbook programatically trooper665 Excel Programming 2 June 17th 05 09:19 PM
Programatically sending a sheet through Outlook Mark Scott[_4_] Excel Programming 11 February 10th 05 05:04 PM
Programatically Breaking Links of Copied Chart Sheet Matthew Wieder Excel Programming 1 July 18th 03 04:58 AM


All times are GMT +1. The time now is 02:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"