Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default activate last worksheet in a different workbook

Hi

I'm trying to write a macro that will need to copy the last worksheet from a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September 06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default activate last worksheet in a different workbook

Perhaps the best way would be to cycle through all of the worksheets and
store the name of it in each loop. then when the loop finished you have the
name of the last worksheet in the workbook stored.

For example:

dim wsheet as worksheet
dim LastWorkSheetName as string
For Each wsheet In Worksheets
LastWorkSheetName = wsheet.NAME
Next wsheet

"Aaron" wrote in message
...
Hi

I'm trying to write a macro that will need to copy the last worksheet from
a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September
06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default activate last worksheet in a different workbook

bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy



"Aaron" wrote:

Hi

I'm trying to write a macro that will need to copy the last worksheet from a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September 06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default activate last worksheet in a different workbook

Hi

Thanks to you both. VBA code is not something I'm overfamiliar with, as a
result I have little idea what either of these solutions is actually meant to
do, or how to "customise" them so they refer to the specific workbooks I'm
trying to fiddle with. Could you possibly let me know which parts I need to
change to make this work with my workbooks?

Thanks

"Tom Ogilvy" wrote:

bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy



"Aaron" wrote:

Hi

I'm trying to write a macro that will need to copy the last worksheet from a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September 06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default activate last worksheet in a different workbook

dim bk as Workbook
set bk = Workbooks("DifferentBook.xls")
bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy


"Aaron" wrote:

Hi

Thanks to you both. VBA code is not something I'm overfamiliar with, as a
result I have little idea what either of these solutions is actually meant to
do, or how to "customise" them so they refer to the specific workbooks I'm
trying to fiddle with. Could you possibly let me know which parts I need to
change to make this work with my workbooks?

Thanks

"Tom Ogilvy" wrote:

bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy



"Aaron" wrote:

Hi

I'm trying to write a macro that will need to copy the last worksheet from a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September 06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default activate last worksheet in a different workbook

Thanks Tom, think I see how it works now. Simplified it a bit to this, seems
to do the trick:

Workbooks.Open "s:\Otherworkbook.xls"
Worksheets(Worksheets.Count).Activate

Presume your code does it without needing to open the other workbook first!

"Tom Ogilvy" wrote:

dim bk as Workbook
set bk = Workbooks("DifferentBook.xls")
bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy


"Aaron" wrote:

Hi

Thanks to you both. VBA code is not something I'm overfamiliar with, as a
result I have little idea what either of these solutions is actually meant to
do, or how to "customise" them so they refer to the specific workbooks I'm
trying to fiddle with. Could you possibly let me know which parts I need to
change to make this work with my workbooks?

Thanks

"Tom Ogilvy" wrote:

bk.sheets(sheets.count).copy After:=Thisworkbook _
.Sheets(thisworkbook.Sheets.count)

--
Regards,
Tom Ogilvy



"Aaron" wrote:

Hi

I'm trying to write a macro that will need to copy the last worksheet from a
different workbook into the one I'm working on. The last worksheet changes
each month (ie, presently it's August 06, next month it will be September 06
etc.), so I can't refer to it by name, and don't think by index numbers.
Anyone know of a way to do this?

Thanks

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
Workbook.Activate / Window.Activate problem Tim[_44_] Excel Programming 3 February 3rd 06 11:38 PM
Activate workbook TimT Excel Programming 5 November 29th 05 08:41 PM
Activate Other Workbook pauluk[_37_] Excel Programming 16 April 20th 04 07:02 PM
Activate Workbook Molly Johnson Excel Programming 1 February 10th 04 05:09 PM
Activate Workbook Fred[_16_] Excel Programming 1 December 2nd 03 05:15 PM


All times are GMT +1. The time now is 05:07 PM.

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"