Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I write VB to run Macro when sheet selected?

I am trying to write VB code to cause a Macro to run when a particular
worksheet is selected. How do I write this code and where do I place it?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default How do I write VB to run Macro when sheet selected?

I am trying to write VB code to cause a Macro to run when a particular
worksheet is selected. How do I write this code and where do I place it?


The code is the same as any other VB code... whatever you need it to do.

You place it in the worksheet's code mudule...

In the VB window, press View-Project Explorer
Double click the sheet that you want the code to work with
Use the drop box in the upper left and select 'Worksheet'
Use the drop box in the upper right to select 'Activate'

When you do that, a subroutine will come up that looks like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Each time the sheet is activated, that code will run.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do I write VB to run Macro when sheet selected?

Think Mark copied the wrong event declaration:

Private Sub Worksheet_Activate()

End Sub

is what he describes.

--
Regards,
Tom Ogilvy


"mark" wrote in message
...
I am trying to write VB code to cause a Macro to run when a particular
worksheet is selected. How do I write this code and where do I place

it?

The code is the same as any other VB code... whatever you need it to do.

You place it in the worksheet's code mudule...

In the VB window, press View-Project Explorer
Double click the sheet that you want the code to work with
Use the drop box in the upper left and select 'Worksheet'
Use the drop box in the upper right to select 'Activate'

When you do that, a subroutine will come up that looks like this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Each time the sheet is activated, that code will run.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default How do I write VB to run Macro when sheet selected?

Think Mark copied the wrong event declaration:


Yep, I sure did.

Thanks for the catch.
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
Write macro to lock selected sheet when run office3000 Excel Discussion (Misc queries) 1 October 14th 08 06:49 PM
how do i write a macro to move down in the sheet one line ? surelystumped New Users to Excel 2 August 30th 06 05:44 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
How do I write a macro copies a column to another sheet but that . Husker87 Excel Programming 2 February 6th 05 04:29 AM
how to allow macro to write on a protected sheet MVM Excel Programming 0 January 18th 05 05:05 PM


All times are GMT +1. The time now is 10:33 PM.

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

About Us

"It's about Microsoft Excel"