Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using Application Events

I am trying to use the Application events to check what sheets are being
activated by the user and then execute code accordingly. While this seems
to work fine on my PC, when I create an add-in and load it on another PC it
does not necessarily work (in some cases it does, in others it doesn't). In
those cases where it does not work the whole event is ignored. Anybody with
any experience on this?

The code I use is as follows:

'In the ThisWorkbook module
Dim WithEvents App As Application

Private Sub Workbook_Open()
Set App = Application
End Sub

Private Sub App_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
'code
End Select
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using Application Events

This is what you should so

Firstly, all of this code goes in the designated workbook.

'========================================
Insert a class module, rename it to 'clsAppEvents', with this code

Option Explicit

Public WithEvents App As Application

Private Sub App_WorkbookBeforePrint(ByVal Wb As Workbook, Cancel As Boolean)
With Wb.ActiveSheet
.PageSetup.LeftFooter = "some text"
End With
End Sub

'========================================
In ThisWorkbook code module, add this event code

Dim AppClass As New clsAppEvents

Private Sub Workbook_Open()

Set AppClass.App = Application

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Thomas Herr" wrote in message
...
I am trying to use the Application events to check what sheets are being
activated by the user and then execute code accordingly. While this seems
to work fine on my PC, when I create an add-in and load it on another PC

it
does not necessarily work (in some cases it does, in others it doesn't).

In
those cases where it does not work the whole event is ignored. Anybody

with
any experience on this?

The code I use is as follows:

'In the ThisWorkbook module
Dim WithEvents App As Application

Private Sub Workbook_Open()
Set App = Application
End Sub

Private Sub App_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
'code
End Select
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
BAC BAC is offline
external usenet poster
 
Posts: 1
Default Using Application Events

Your "event ignoring machines" may need to have the Events
handler activated try adding --- Lines below:
Dim WithEvents App As Application


---Application.EnableEvents = True

Private Sub Workbook_Open()
Set App = Application
End Sub


Private Sub App_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
'code
End Select


---Application.EnableEvents = False
---ActiveWorkbook.Save

End Sub


BAC


-----Original Message-----
I am trying to use the Application events to check what

sheets are being
activated by the user and then execute code accordingly.

While this seems
to work fine on my PC, when I create an add-in and load

it on another PC it
does not necessarily work (in some cases it does, in

others it doesn't). In
those cases where it does not work the whole event is

ignored. Anybody with
any experience on this?

The code I use is as follows:

'In the ThisWorkbook module
Dim WithEvents App As Application

Private Sub Workbook_Open()
Set App = Application
End Sub

Private Sub App_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
'code
End Select
End Sub


.

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
events? [email protected] Excel Discussion (Misc queries) 1 September 14th 05 03:26 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
How-To - Forwarding Excel 2000 events to .Net application Joel Foner Excel Programming 0 January 28th 04 11:34 PM
application.quit will not shut off application john Excel Programming 0 January 9th 04 11:29 PM
events Mark[_17_] Excel Programming 1 October 29th 03 12:56 PM


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