PC Review


Reply
Thread Tools Rate Thread

Can't get Sheet_Change event to fire - please help

 
 
willjohnson33@yahoo.com
Guest
Posts: n/a
 
      30th Nov 2006
Ok, I searched the boards and found thomas cool's solution to making an
event fire from any sheet or worksheet without using class modules. I
have the following code in ThisWorkbook of my add-in

Private Sub xlsMonitor_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
On Error Resume Next
Application.EnableEvents = False
If ActiveCell.Comment.text <> "" Then
Application.StatusBar = ActiveCell.Comment.text
Else
Application.StatusBar = False
End If
Application.EnableEvents = True
End Sub

All I am trying to do is set it up so that any time I am in a cell with
a comment, the comment is displayed in the status bar. I was able to
get similar code to work when I put the code in ThisWorkbook of an
actual workbook using Private Sub Workbook_SheetChange(ByVal Sh As
Object, ByVal Target As Range)


Why will this not work? Any help is greatly appreciated.

Will

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      30th Nov 2006
Are you trying to create a short cut way of using application Level events ?
Your code will only respond when changes are made in the workbook
"xlsMonitor", not any sheet.
Also is this really an add-in ?
As such, it is not visible and having code in the _Change event makes no
sense.

Follow Chip's method:
http://www.cpearson.com/excel/AppEvent.htm

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok, I searched the boards and found thomas cool's solution to making an
> event fire from any sheet or worksheet without using class modules. I
> have the following code in ThisWorkbook of my add-in
>
> Private Sub xlsMonitor_SheetChange(ByVal Sh As Object, ByVal Target As
> Range)
> On Error Resume Next
> Application.EnableEvents = False
> If ActiveCell.Comment.text <> "" Then
> Application.StatusBar = ActiveCell.Comment.text
> Else
> Application.StatusBar = False
> End If
> Application.EnableEvents = True
> End Sub
>
> All I am trying to do is set it up so that any time I am in a cell with
> a comment, the comment is displayed in the status bar. I was able to
> get similar code to work when I put the code in ThisWorkbook of an
> actual workbook using Private Sub Workbook_SheetChange(ByVal Sh As
> Object, ByVal Target As Range)
>
>
> Why will this not work? Any help is greatly appreciated.
>
> Will
>



 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      30th Nov 2006
This modified code placed in the ThisWorkbook module
works for me. The Workbook_Open sub must run first...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


Option Explicit
Public WithEvents xlsMonitor As Excel.Application

Private Sub xlsMonitor_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error GoTo EnoughSaid
Dim rngCom As Object
xlsMonitor.EnableEvents = False
On Error Resume Next
Set rngCom = Target.Comment
On Error GoTo EnoughSaid
If Not rngCom Is Nothing Then
xlsMonitor.StatusBar = rngCom.Text
Else
xlsMonitor.StatusBar = False
End If
EnoughSaid:
Set rngCom = Nothing
xlsMonitor.EnableEvents = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set xlsMonitor = Nothing
End Sub

Private Sub Workbook_Open()
Set xlsMonitor = Excel.Application
xlsMonitor.EnableEvents = True
End Sub
'-------------


<(E-Mail Removed)>
wrote in message
Ok, I searched the boards and found thomas cool's solution to making an
event fire from any sheet or worksheet without using class modules. I
have the following code in ThisWorkbook of my add-in

Private Sub xlsMonitor_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
On Error Resume Next
Application.EnableEvents = False
If ActiveCell.Comment.text <> "" Then
Application.StatusBar = ActiveCell.Comment.text
Else
Application.StatusBar = False
End If
Application.EnableEvents = True
End Sub

All I am trying to do is set it up so that any time I am in a cell with
a comment, the comment is displayed in the status bar. I was able to
get similar code to work when I put the code in ThisWorkbook of an
actual workbook using Private Sub Workbook_SheetChange(ByVal Sh As
Object, ByVal Target As Range)
Why will this not work? Any help is greatly appreciated.
Will

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      30th Nov 2006
And as NickHK mentioned this will not work in an add-in.
Jim Cone
San Francisco, USA



"Jim Cone" <(E-Mail Removed)>
wrote in message
This modified code placed in the ThisWorkbook module
works for me. The Workbook_Open sub must run first...
-snip-
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

 
Reply With Quote
 
willjohnson33@yahoo.com
Guest
Posts: n/a
 
      30th Nov 2006
Thanks for the replies. I created an event class and then modified
Jim's code slightly and it works. Yes, this is in an add-in.



Jim Cone wrote:
> And as NickHK mentioned this will not work in an add-in.
> Jim Cone
> San Francisco, USA
>
>
>
> "Jim Cone" <(E-Mail Removed)>
> wrote in message
> This modified code placed in the ThisWorkbook module
> works for me. The Workbook_Open sub must run first...
> -snip-
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 wont run 2003 coded sheet_change event. Grid Microsoft Excel Programming 1 20th Jan 2010 02:12 PM
ImageButton event doesn't fire but Button event does suzanne.boyle@gmail.com Microsoft ASP .NET 4 13th Jun 2007 10:19 PM
fire event from another event scroll 2 datagrids together tartasuga Microsoft Dot NET Framework 0 7th Oct 2005 07:50 PM
SelectedIndexChanged event in comboA causes same event to fire in comboB moondaddy Microsoft Dot NET Framework Forms 5 29th Sep 2004 04:04 AM
When does SelectedIndexChanged event fire & an alternative to this event? moondaddy Microsoft Dot NET Framework Forms 2 1st Nov 2003 07:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:14 PM.