Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Attaching code to ThisWorkbook

I placed this code under ThisWorkbook but it does not run. If I place the
code on a worksheet it runs fine for that worksheet. My workbook has over 90
worksheets. I was hoping not to have to attach this code to each worksheet.
Am I missing something?



Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.range)

If Not Application.Intersect(Target, range("H11:H22")) Is Nothing Then
VacationTaken.Show


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Attaching code to ThisWorkbook

Double click This workbook. and drop down to get the below event

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)

If Not Application.Intersect(Target, range("H11:H22")) Is Nothing Then
VacationTaken.Show

End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Patrick C. Simonds" wrote:

I placed this code under ThisWorkbook but it does not run. If I place the
code on a worksheet it runs fine for that worksheet. My workbook has over 90
worksheets. I was hoping not to have to attach this code to each worksheet.
Am I missing something?



Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.range)

If Not Application.Intersect(Target, range("H11:H22")) Is Nothing Then
VacationTaken.Show


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Attaching code to ThisWorkbook

selection change is a workSHEET event, and should be in the worksheet for
which you want to trap the event. Sheet Selection Change is the workbook
event, and this should be in the code page for ThisWorkbook.
HINT: in the code module for the worksheet, your objects are Worksheet and
general, for ThisWorkbook, the objects are Workbook and general

"Patrick C. Simonds" wrote:

I placed this code under ThisWorkbook but it does not run. If I place the
code on a worksheet it runs fine for that worksheet. My workbook has over 90
worksheets. I was hoping not to have to attach this code to each worksheet.
Am I missing something?



Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.range)

If Not Application.Intersect(Target, range("H11:H22")) Is Nothing Then
VacationTaken.Show


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Attaching code to ThisWorkbook

Just to add...

I wouldn't type those events. Use the dropdown and choose the event that you
want. All you can do by typing is screw it up <vbg.

And on top of that, I'd qualify the range, too:

Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)

If Application.Intersect(Target, Sh.Range("H11:H22")) Is Nothing Then
'do nothing
Else
vacationTaken.Show
End If

End Sub

I didn't use "not" just because I find this syntax easier to understand. But
it's a personal choice.



"Patrick C. Simonds" wrote:

I placed this code under ThisWorkbook but it does not run. If I place the
code on a worksheet it runs fine for that worksheet. My workbook has over 90
worksheets. I was hoping not to have to attach this code to each worksheet.
Am I missing something?

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.range)

If Not Application.Intersect(Target, range("H11:H22")) Is Nothing Then
VacationTaken.Show

End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Attaching code to ThisWorkbook

On Apr 15, 12:26*pm, "Patrick C. Simonds"
wrote:
I placed this code under *ThisWorkbook *but it does not run. If I place the
code on a worksheet it runs fine for that worksheet. My workbook has over 90
worksheets. I was hoping not to have to attach this code to each worksheet.

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
Copy code from ThisWorkbook using VBA? RayportingMonkey Excel Programming 1 August 26th 08 08:17 PM
Turn off ThisWorkbook Code? [email protected] Excel Programming 3 April 12th 07 02:29 PM
Deleting Code in 'ThisWorkbook' Ken Loomis Excel Programming 4 March 25th 05 01:36 PM
Attaching a macro (module) code to button Todd Huttenstine[_2_] Excel Programming 1 December 29th 03 09:12 AM
Delete the code in ThisWorkbook Darrin Henry Excel Programming 1 October 1st 03 11:10 PM


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