Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / July 2008

Tip: Looking for answers? Try searching our database.

Insert New Sheet De-activates Current Sheet VBA Workaround?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
facmanboss - 30 Jul 2008 00:33 GMT
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
Gord Dibben - 30 Jul 2008 01:09 GMT
Set prior = ActiveSheet
With Worksheets.Add
         'run your code on added sheet
End With
prior.Activate

Gord Dibben  MS Excel MVP

>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
[quoted text clipped - 3 lines]
>Thanks in advance,
>facmanboss
facmanboss - 30 Jul 2008 16:49 GMT
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.

> Set prior = ActiveSheet
> With Worksheets.Add
[quoted text clipped - 11 lines]
> >Thanks in advance,
> >facmanboss
Gord Dibben - 31 Jul 2008 01:00 GMT
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

>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
[quoted text clipped - 20 lines]
>> >Thanks in advance,
>> >facmanboss
facmanboss - 31 Jul 2008 16:51 GMT
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.

> You wrote of using code to do something to the new sheet after it is
> inserted/added.
[quoted text clipped - 7 lines]
>
> Gord
Gord Dibben - 31 Jul 2008 20:00 GMT
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

>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
[quoted text clipped - 14 lines]
>>
>> Gord
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.