Public variable not recognized in event

K

kblum

I have created a macro that runs through a bunch of cells adjusting dat
in other cells. I want this macro to be run whenever there is a chang
(DDE) in some cells, so I thought I would just put a cal
"Application.Run MyMacro
" in the Worksheet_Change event. However when I did that it resulte
in Out of Stack Space errors because the macro itself would change dat
on the worksheet. So I thought I would create a Public Variable in th
Workbook Global Declarations as "Public glRecChanges As Boolean", an
then put this in the Worksheet_Change event...


Code
-------------------
Private Sub Worksheet_Change(ByVal Target As Range)
If !glRecChanges Then
glRecChanges = True

Application.Run "'CWServ NetDDE Test.xls'!RecordChanges"
glRecChanges = False
End If
End Su
-------------------


However it says that the glRecChanges is an "Invalid or Unqualifie
Reference".

What am I doing wrong?

TIA,

Ke
 
T

Tom Ogilvy

Better would be

Private Sub Worksheet_Change(ByVal Target As Range)
On Error goto ErrHandler
Application.Events = False
RecordChanges
ErrHandler:
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top