LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Can't get Application Events to work with .xla

I am trying to create a shortcut method for toggling between Auto/Manual
calculation mode. I have two menu items, one in the right-click menu and
one off of the worksheet menu. As part of both menu items, I update the
..State property based on Auto or Manual. In order to make this work if the
user chooses the Tool/Options method of changing calculation mode I am
attempting to use a class module/WithEvents with various application events.
The code below works fine when I run it from the .xls file, however, as soon
as I save/install it as an .xla file I get a 'Run-time error 13: Type
mismatch' error at the commented line in the InitCalcMode procedure.

I have tried eliminating the Call InitCalcMode in the Open procedure
thinking the workbook open event would capture it, moved the Set AppClass
line in the Open procedure to the last line, and tried changing the If
Application.Calculation to If App.Calculation and If AppClass.App with no
luck. I am guessing that there is something different about programming for
..xla mode vs .xls but I don't know what it is. Any help is greatly
appreciated and sorry for the long post but I wanted to give as much
information as I could. BTW, I am using XL2003 and WinXP.

In the ThisWorkbook module:

Option Explicit
Dim AppClass As New clsEventClass

Private Sub Workbook_Open()
Set AppClass.App = Application
Call MakeMenu
Call InitCalcMode
Application.OnKey "+^{D}", "modStartEndTime.StartEndTime"
End Sub


In a class module named clsEventClass:

Option Explicit
Public WithEvents App As Application

Private Sub App_NewWorkbook(ByVal Wb As Excel.Workbook)
Call InitCalcMode
End Sub

Private Sub App_SheetActivate(ByVal Sh As Object)
Call InitCalcMode
End Sub

Private Sub App_SheetCalculate(ByVal Sh As Object)
Call InitCalcMode
End Sub

Private Sub App_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)
Call InitCalcMode
End Sub

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)
Call InitCalcMode
End Sub


In a general code module:

Sub InitCalcMode()
Dim oCtrl1 As CommandBarButton, oCtrl2 As CommandBarButton

On Error Resume Next
Set oCtrl1 = CommandBars(1).FindControl(Tag:="PIMS
TIPS").Controls("AutoCalc")
Set oCtrl2 = CommandBars("Cell").FindControl(Tag:="PIMS
TIPS").Controls("AutoCalc")
On Error GoTo 0

If Application.Calculation = xlCalculationAutomatic Then ****Error
occurs here****
oCtrl1.State = msoButtonDown
oCtrl1.ShortcutText = "AutoCalc ON"
oCtrl2.State = msoButtonDown
oCtrl2.ShortcutText = "AutoCalc ON"
Else
oCtrl1.State = msoButtonUp
oCtrl1.ShortcutText = "AutoCalc OFF"
oCtrl2.State = msoButtonUp
oCtrl2.ShortcutText = "AutoCalc OFF"
End If
End Sub


 
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
Application level events John Excel Programming 1 November 25th 05 07:22 PM
Application events ben Excel Programming 29 July 21st 05 04:12 PM
Application Events / App_WorkbookOpen Fries[_2_] Excel Programming 5 December 18th 04 01:21 PM
Application Level Events Question nickg420[_4_] Excel Programming 3 July 16th 04 05:02 PM
Using Application Events Thomas Herr Excel Programming 2 April 5th 04 09:24 PM


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