Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

When I insert a new sheet in a workbook, there are some things I do to it via
VBA code before it finishes activating. However, I would like to restore the
sheet that was active PRIOR to the insert as the active one after the new
sheet finishes it's setup. The events available in Excel don't seem amenable
to this. How can I do this with VBA code?
Thanks in advance,
facmanboss
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

Set prior = ActiveSheet
With Worksheets.Add
'run your code on added sheet
End With
prior.Activate


Gord Dibben MS Excel MVP

On Tue, 29 Jul 2008 16:33:01 -0700, facmanboss
wrote:

When I insert a new sheet in a workbook, there are some things I do to it via
VBA code before it finishes activating. However, I would like to restore the
sheet that was active PRIOR to the insert as the active one after the new
sheet finishes it's setup. The events available in Excel don't seem amenable
to this. How can I do this with VBA code?
Thanks in advance,
facmanboss


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

Thanks. I wasn't clear in my description. My bad. This looks like it works
fine from code being run to add a new sheet. Here is my scenario. The user
selects the Excel Menu Insert-Worksheet. No code involved, Excel does it.
Excel changes the activesheet to the new one.

I can't figure out how to make the prior sheet active again since there is
no code running to test with and the user needs to be able to use the Insert
menu only to add a new sheet.

"Gord Dibben" wrote:

Set prior = ActiveSheet
With Worksheets.Add
'run your code on added sheet
End With
prior.Activate


Gord Dibben MS Excel MVP

On Tue, 29 Jul 2008 16:33:01 -0700, facmanboss
wrote:

When I insert a new sheet in a workbook, there are some things I do to it via
VBA code before it finishes activating. However, I would like to restore the
sheet that was active PRIOR to the insert as the active one after the new
sheet finishes it's setup. The events available in Excel don't seem amenable
to this. How can I do this with VBA code?
Thanks in advance,
facmanboss



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

You wrote of using code to do something to the new sheet after it is
inserted/added.

When/how do you activate that code?

Why not just add the code I posted at the top of your code and assign it all
to a button?

Tell users to hit the button when inserting a new sheet.


Gord

On Wed, 30 Jul 2008 08:49:02 -0700, facmanboss
wrote:

Thanks. I wasn't clear in my description. My bad. This looks like it works
fine from code being run to add a new sheet. Here is my scenario. The user
selects the Excel Menu Insert-Worksheet. No code involved, Excel does it.
Excel changes the activesheet to the new one.

I can't figure out how to make the prior sheet active again since there is
no code running to test with and the user needs to be able to use the Insert
menu only to add a new sheet.

"Gord Dibben" wrote:

Set prior = ActiveSheet
With Worksheets.Add
'run your code on added sheet
End With
prior.Activate


Gord Dibben MS Excel MVP

On Tue, 29 Jul 2008 16:33:01 -0700, facmanboss
wrote:

When I insert a new sheet in a workbook, there are some things I do to it via
VBA code before it finishes activating. However, I would like to restore the
sheet that was active PRIOR to the insert as the active one after the new
sheet finishes it's setup. The events available in Excel don't seem amenable
to this. How can I do this with VBA code?
Thanks in advance,
facmanboss




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

Unfortunately, that's the obvious way. We don't want end users having to
perform an action for this to occur. I was hoping there was a way to
intercept the Menu Insert-Worksheet such that it would invoke some of my
code where I could add the new sheet per your suggestion rather than letting
Excel do it. If there isn't an easy way, then it isn't worth pursuing.
Thanks.

"Gord Dibben" wrote:

You wrote of using code to do something to the new sheet after it is
inserted/added.

When/how do you activate that code?

Why not just add the code I posted at the top of your code and assign it all
to a button?

Tell users to hit the button when inserting a new sheet.


Gord



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Insert New Sheet De-activates Current Sheet VBA Workaround?

Place in Thisworkbook module

Private Sub Workbook_NewSheet(ByVal Sh As Object)
'run the code to do whatever on the new sheet
're-activate the original sheet
End Sub


Gord

On Thu, 31 Jul 2008 08:51:05 -0700, facmanboss
wrote:

Unfortunately, that's the obvious way. We don't want end users having to
perform an action for this to occur. I was hoping there was a way to
intercept the Menu Insert-Worksheet such that it would invoke some of my
code where I could add the new sheet per your suggestion rather than letting
Excel do it. If there isn't an easy way, then it isn't worth pursuing.
Thanks.

"Gord Dibben" wrote:

You wrote of using code to do something to the new sheet after it is
inserted/added.

When/how do you activate that code?

Why not just add the code I posted at the top of your code and assign it all
to a button?

Tell users to hit the button when inserting a new sheet.


Gord


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
Insert Current Date on a Sheet 1 Tab Veronica Excel Worksheet Functions 6 February 13th 08 04:30 PM
Preventing sheet name changes (or a workaround) Barb Reinhardt Excel Programming 6 August 7th 06 08:45 PM
UDF is updateing cells on another sheet with count from current sheet. John[_116_] Excel Programming 2 March 20th 06 10:37 PM
Return to Current Sheet in On (sheet activate) event macro Paul Moles Excel Programming 1 March 27th 05 03:16 PM
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B Hannes Heckner Excel Programming 1 March 5th 04 09:10 AM


All times are GMT +1. The time now is 05:14 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"