View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

Hi Norman.

I tried to understand your suggestions, but I couldn't apply them to my
case. So I post the code of Workbook_SheetCalculate and the UDF hoping you
can give me some more useful advices.

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Worksheets("Jelentés").CommandButton1.Enabled = _
Names("megvane").RefersToRange.Item(1, 1) And _
Names("megvane").RefersToRange.Item(1, 2) And _
Names("megvane").RefersToRange.Item(2, 1) And _
Names("megvane").RefersToRange.Item(2, 2)
Worksheets("Jelentés").CommandButton3.Enabled = _
Names("megvane").RefersToRange.Item(2, 3)
Worksheets("Jelentés").CommandButton2.Enabled = _
Names("megvane").RefersToRange.Item(3, 1) And _
Names("megvane").RefersToRange.Item(3, 2)
Worksheets("Jelentés").CommandButton4.Enabled = _
Names("megvane").RefersToRange.Item(3, 3)
End Sub

The UDF:
Public Function FileExists(fname, Optional most As Date) As Boolean
Application.Volatile
FileExists = False
On Error Resume Next
FileExists = IIf(Dir(fname) < "", True, False)
End Function

Range "megvane" is in another sheet named "segéd", range("G3:I5"), the first
item (G3) contains
=fileexists(Jelentés!$B3&Jelentés!G3)

which is filled to the right and down throghout the range.
Jelentés!$B3 contains folder name,
Jelentés!G3 contains file name
of files existence of which is to be checked. The do not change, therefore
UDF is not recalculated. I'd like that the UDF be recalculated when pressing
F9, to re-check the existence of the files.

How can I do that without Volatile

Regards,
Stefi

Norman Jones ezt *rta:

Hi Steffi,

Without seeing your UDF, it is difficult to
give a useful response.

However, you can set the Application.Volatile
statement to false in your UDF.

Also, you should pass all references to cells
as parameters to your UDF. In this way, the
UDF will be recalculated whenever any of
the cells change. This will obviate the need
for an Application.Volatile statement which
is slow.



---
Regards.
Norman


"Stefi" wrote in message
...
Hi Norman,

Im the meantime I discovered that Workbook_SheetCalculate event was
triggered not by enabling/disabling a commandbutton but by a volatile UDF
in
some cells. Pressing F9 started Calculation (and triggered
Workbook_SheetCalculate first time)therefore the volatile UDF was
evaluated
changing cell values, changing cell values started a new Calculation which
triggered Workbook_SheetCalculate second time.

The question is now how can I reduce No of executing
Workbook_SheetCalculate
to one? I do need volatile nature of the UDF!

Regards,
Stefi

Norman Jones ezt *rta:

Hi Steffi.

Try posting the code for the CommandButton.



---
Regards.
Norman


"Stefi" wrote in message
...
Hi All,

Is a Workbook_SheetCalculate event triggered by enabling/disabling a
control, e.g. a commandbutton? I have one doing nothing else, and it
seems
to
trigger itself again. Is it possible? If so, how can I avoid it to
happen?

Thanks,
Stefi