Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
SLL SLL is offline
external usenet poster
 
Posts: 5
Default VBA: Worksheet_Calculate() Not being called

All-

I have read plenty about how people feel that their
worksheet_calculate gets called too often, but how about my situation:
It never gets called, and I am not so sure why.

I tried recalcing the sheet but the event never seems to get called.
when I open the file though, it does get called. I am very confused.
Any help woudl be appreciated. Thanks.

Here is the code for my worksheet:

Option Explicit

Dim StartProg As Boolean

Dim i As Integer

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PlayWAV(File As String)

Call PlaySound(File, 0&, SND_ASYNC Or SND_FILENAME)

End Sub

Private Sub ResetButton_Click()
Worksheets("Front").Range("B3") = ""
End Sub

Private Sub StopButton_Click()

Application.EnableEvents = False
Call PlayWAV("C:\sounds\Down.wav")
Worksheets("Front").Range("B3") = ""
Worksheets("Feeds").Range("G1").Value = "OFF"
StartProg = False
Application.EnableEvents = True

End Sub

Private Sub StartButton_Click()

Call PlayWAV("C:\sounds\Up.wav")
StartProg = True

End Sub


Sub Worksheet_Calculate()

Application.EnableEvents = False

If StartProg = True Then
Worksheets("Feeds").Range("G1").Value = "ON"
Call PlayWAV("C:\sounds\drumroll.wav")

'Instructions, calcuations, etc

Application.EnableEvents = True

'Instructions, calcuations, etc

End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 857
Default VBA: Worksheet_Calculate() Not being called

SLL,

Your code turns off events at the start of the calculate event. But, if
StartProg < True, it never gets turned back on. So try moving this line

Application.EnableEvents = True

outside of the If statement.


Sub Worksheet_Calculate()

Application.EnableEvents = False

If StartProg = True Then
Worksheets("Feeds").Range("G1").Value = "ON"
Call PlayWAV("C:\sounds\drumroll.wav")

'Instructions, calcuations, etc

'Instructions, calcuations, etc
End If

Application.EnableEvents = True

End Sub


--
Hope that helps.

Vergel Adriano


"SLL" wrote:

All-

I have read plenty about how people feel that their
worksheet_calculate gets called too often, but how about my situation:
It never gets called, and I am not so sure why.

I tried recalcing the sheet but the event never seems to get called.
when I open the file though, it does get called. I am very confused.
Any help woudl be appreciated. Thanks.

Here is the code for my worksheet:

Option Explicit

Dim StartProg As Boolean

Dim i As Integer

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PlayWAV(File As String)

Call PlaySound(File, 0&, SND_ASYNC Or SND_FILENAME)

End Sub

Private Sub ResetButton_Click()
Worksheets("Front").Range("B3") = ""
End Sub

Private Sub StopButton_Click()

Application.EnableEvents = False
Call PlayWAV("C:\sounds\Down.wav")
Worksheets("Front").Range("B3") = ""
Worksheets("Feeds").Range("G1").Value = "OFF"
StartProg = False
Application.EnableEvents = True

End Sub

Private Sub StartButton_Click()

Call PlayWAV("C:\sounds\Up.wav")
StartProg = True

End Sub


Sub Worksheet_Calculate()

Application.EnableEvents = False

If StartProg = True Then
Worksheets("Feeds").Range("G1").Value = "ON"
Call PlayWAV("C:\sounds\drumroll.wav")

'Instructions, calcuations, etc

Application.EnableEvents = True

'Instructions, calcuations, etc

End If

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
SLL SLL is offline
external usenet poster
 
Posts: 5
Default VBA: Worksheet_Calculate() Not being called

On May 1, 9:01 pm, Vergel Adriano
wrote:
SLL,

Your code turns off events at the start of the calculate event. But, if
StartProg < True, it never gets turned back on. So try moving this line

Application.EnableEvents = True

outside of the If statement.

Sub Worksheet_Calculate()

Application.EnableEvents = False

If StartProg = True Then
Worksheets("Feeds").Range("G1").Value = "ON"
Call PlayWAV("C:\sounds\drumroll.wav")

'Instructions, calcuations, etc

'Instructions, calcuations, etc
End If

Application.EnableEvents = True

End Sub

--
Hope that helps.

Vergel Adriano



"SLL" wrote:
All-


I have read plenty about how people feel that their
worksheet_calculate gets called too often, but how about my situation:
It never gets called, and I am not so sure why.


I tried recalcing the sheet but the event never seems to get called.
when I open the file though, it does get called. I am very confused.
Any help woudl be appreciated. Thanks.


Here is the code for my worksheet:


Option Explicit


Dim StartProg As Boolean


Dim i As Integer


Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000


Sub PlayWAV(File As String)


Call PlaySound(File, 0&, SND_ASYNC Or SND_FILENAME)


End Sub


Private Sub ResetButton_Click()
Worksheets("Front").Range("B3") = ""
End Sub


Private Sub StopButton_Click()


Application.EnableEvents = False
Call PlayWAV("C:\sounds\Down.wav")
Worksheets("Front").Range("B3") = ""
Worksheets("Feeds").Range("G1").Value = "OFF"
StartProg = False
Application.EnableEvents = True


End Sub


Private Sub StartButton_Click()


Call PlayWAV("C:\sounds\Up.wav")
StartProg = True


End Sub


Sub Worksheet_Calculate()


Application.EnableEvents = False


If StartProg = True Then
Worksheets("Feeds").Range("G1").Value = "ON"
Call PlayWAV("C:\sounds\drumroll.wav")


'Instructions, calcuations, etc


Application.EnableEvents = True


'Instructions, calcuations, etc


End If


End Sub- Hide quoted text -


- Show quoted text -


Thanks...Looked like I was staring at this a bit too long.

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
worksheet_calculate enyaw Excel Discussion (Misc queries) 2 January 26th 07 01:16 PM
worksheet_calculate enyaw Excel Discussion (Misc queries) 0 January 26th 07 08:14 AM
Worksheet_Calculate Question Volsfan Excel Programming 2 September 17th 05 09:51 AM
Worksheet_calculate() Alex Excel Programming 1 August 30th 05 10:09 PM
worksheet_calculate **help** tommyboy Excel Programming 2 June 29th 04 08:33 AM


All times are GMT +1. The time now is 10:36 AM.

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"