Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default triggering Workbook_SheetCalculate

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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default triggering Workbook_SheetCalculate

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
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






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default triggering Workbook_SheetCalculate

Hi Steffi,

I removed the Application Volatile instruction
from your UDF.

Changing the values of (say) cells B3 or G3 on
the Jelentés worksheet updates the cell containing
the formula:

=fileexists(Jelentés!$B3&Jelentés!G3)

on the Segéd sheet



---
Regards.
Norman


"Stefi" wrote in message
...
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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default triggering Workbook_SheetCalculate

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it seems to me
that you only want the workbook_sheetcalculate sub to run when FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

Hi Charles,

Thank you for your post, I was giving up hope to solve this problem. I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing =Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells when
pressing F9.
What I'd like to happen when pressing F9 is first to check the existence of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range "megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many cells
range "megvane" has plus once for Calculate triggered by F9. I tried to place
Application.EnableEvents = False as the first line of Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it back to
True. Placing it as the last line of Workbook_SheetCalculate code re creates
the problem.

Regards,
Stefi




€žCharles Williams€ ezt Ã*rta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it seems to me
that you only want the workbook_sheetcalculate sub to run when FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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







  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default triggering Workbook_SheetCalculate

Hi Stefi,

I understand.

Here is what you need to do.

1. copy the workbook_SheetCalculate code
2. In the VBE under VBAProject in the Project Window right-click Sheet
"seged" and select view code
3. On the Seged code module that you have got to create a
worksheet_Calculate sub
4. Paste in the code from Workbook_SheetCalculate
5. Remove the Workbook_SheetCalculate code.

This will stop the workbook_Calculate sub from executing after every sheet
recalcs, and make the code only calculate after the Seged sheet is
calculated (which should be only once per F9).

regards
Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Thank you for your post, I was giving up hope to solve this problem. I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing
=Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells when
pressing F9.
What I'd like to happen when pressing F9 is first to check the existence
of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range
"megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many
cells
range "megvane" has plus once for Calculate triggered by F9. I tried to
place
Application.EnableEvents = False as the first line of
Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it back
to
True. Placing it as the last line of Workbook_SheetCalculate code re
creates
the problem.

Regards,
Stefi




"Charles Williams" ezt írta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it seems to
me
that you only want the workbook_sheetcalculate sub to run when FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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









  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

Many thanks, Charles, I'm going to try it and let you know the result.
Stefi


€žCharles Williams€ ezt Ã*rta:

Hi Stefi,

I understand.

Here is what you need to do.

1. copy the workbook_SheetCalculate code
2. In the VBE under VBAProject in the Project Window right-click Sheet
"seged" and select view code
3. On the Seged code module that you have got to create a
worksheet_Calculate sub
4. Paste in the code from Workbook_SheetCalculate
5. Remove the Workbook_SheetCalculate code.

This will stop the workbook_Calculate sub from executing after every sheet
recalcs, and make the code only calculate after the Seged sheet is
calculated (which should be only once per F9).

regards
Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Thank you for your post, I was giving up hope to solve this problem. I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing
=Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells when
pressing F9.
What I'd like to happen when pressing F9 is first to check the existence
of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range
"megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many
cells
range "megvane" has plus once for Calculate triggered by F9. I tried to
place
Application.EnableEvents = False as the first line of
Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it back
to
True. Placing it as the last line of Workbook_SheetCalculate code re
creates
the problem.

Regards,
Stefi




"Charles Williams" ezt Ã*rta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it seems to
me
that you only want the workbook_sheetcalculate sub to run when FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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












  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

Hi Charles,

Your suggestion almost solved my problem. One question remained: pressing F9
doesn't fire Worksheet_Calculate of Seged if nothing else changes but the
existence of files.

Any further idea?

Regards,
Stefi


€žStefi€ ezt Ã*rta:

Many thanks, Charles, I'm going to try it and let you know the result.
Stefi


€žCharles Williams€ ezt Ã*rta:

Hi Stefi,

I understand.

Here is what you need to do.

1. copy the workbook_SheetCalculate code
2. In the VBE under VBAProject in the Project Window right-click Sheet
"seged" and select view code
3. On the Seged code module that you have got to create a
worksheet_Calculate sub
4. Paste in the code from Workbook_SheetCalculate
5. Remove the Workbook_SheetCalculate code.

This will stop the workbook_Calculate sub from executing after every sheet
recalcs, and make the code only calculate after the Seged sheet is
calculated (which should be only once per F9).

regards
Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Thank you for your post, I was giving up hope to solve this problem. I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing
=Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells when
pressing F9.
What I'd like to happen when pressing F9 is first to check the existence
of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range
"megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many
cells
range "megvane" has plus once for Calculate triggered by F9. I tried to
place
Application.EnableEvents = False as the first line of
Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it back
to
True. Placing it as the last line of Workbook_SheetCalculate code re
creates
the problem.

Regards,
Stefi




"Charles Williams" ezt Ã*rta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it seems to
me
that you only want the workbook_sheetcalculate sub to run when FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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










  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default triggering Workbook_SheetCalculate

Are you sure your fileexists function is ?
- volatile
- used on worksheet Seged


Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Your suggestion almost solved my problem. One question remained: pressing
F9
doesn't fire Worksheet_Calculate of Seged if nothing else changes but the
existence of files.

Any further idea?

Regards,
Stefi


"Stefi" ezt írta:

Many thanks, Charles, I'm going to try it and let you know the result.
Stefi


"Charles Williams" ezt írta:

Hi Stefi,

I understand.

Here is what you need to do.

1. copy the workbook_SheetCalculate code
2. In the VBE under VBAProject in the Project Window right-click Sheet
"seged" and select view code
3. On the Seged code module that you have got to create a
worksheet_Calculate sub
4. Paste in the code from Workbook_SheetCalculate
5. Remove the Workbook_SheetCalculate code.

This will stop the workbook_Calculate sub from executing after every
sheet
recalcs, and make the code only calculate after the Seged sheet is
calculated (which should be only once per F9).

regards
Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Thank you for your post, I was giving up hope to solve this problem.
I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing
=Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells
when
pressing F9.
What I'd like to happen when pressing F9 is first to check the
existence
of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range
"megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many
cells
range "megvane" has plus once for Calculate triggered by F9. I tried
to
place
Application.EnableEvents = False as the first line of
Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it
back
to
True. Placing it as the last line of Workbook_SheetCalculate code re
creates
the problem.

Regards,
Stefi




"Charles Williams" ezt írta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it
seems to
me
that you only want the workbook_sheetcalculate sub to run when
FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub
in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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












  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default triggering Workbook_SheetCalculate

Oh god, it is, I checked it again, and during the repeated test I discovered
the cause of the problem: a control (checkbox) was active and not a
worksheet. Having clicked on the worksheet F9 worked again as prescribed.
What do you think, what is the easiest way to avoid this situation?

Stefi


€žCharles Williams€ ezt Ã*rta:

Are you sure your fileexists function is ?
- volatile
- used on worksheet Seged


Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Your suggestion almost solved my problem. One question remained: pressing
F9
doesn't fire Worksheet_Calculate of Seged if nothing else changes but the
existence of files.

Any further idea?

Regards,
Stefi


"Stefi" ezt Ã*rta:

Many thanks, Charles, I'm going to try it and let you know the result.
Stefi


"Charles Williams" ezt Ã*rta:

Hi Stefi,

I understand.

Here is what you need to do.

1. copy the workbook_SheetCalculate code
2. In the VBE under VBAProject in the Project Window right-click Sheet
"seged" and select view code
3. On the Seged code module that you have got to create a
worksheet_Calculate sub
4. Paste in the code from Workbook_SheetCalculate
5. Remove the Workbook_SheetCalculate code.

This will stop the workbook_Calculate sub from executing after every
sheet
recalcs, and make the code only calculate after the Seged sheet is
calculated (which should be only once per F9).

regards
Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

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

Thank you for your post, I was giving up hope to solve this problem.
I try
to put clear the task:

I have a range named "megvane" in sheet "seged" containing
=Fileexists(...)
UDFs.
Fileexists is volatile because it is required to evaluate these cells
when
pressing F9.
What I'd like to happen when pressing F9 is first to check the
existence
of
files by evaluating =Fileexists(...) in range "megvane" then
enabling/disabling commandbuttons depending on the values of range
"megvane".

The problem is that changing the values in range "megvane" also fires
Workbook_SheetCalculate event so it is executed as many times as many
cells
range "megvane" has plus once for Calculate triggered by F9. I tried
to
place
Application.EnableEvents = False as the first line of
Workbook_SheetCalculate
code, it solved the problem, but cannot find the place to switch it
back
to
True. Placing it as the last line of Workbook_SheetCalculate code re
creates
the problem.

Regards,
Stefi




"Charles Williams" ezt Ã*rta:

Hi Stefi,

Not sure I understand exactly what you are trying to do, but it
seems to
me
that you only want the workbook_sheetcalculate sub to run when
FileExists
has been calculated.

The simplest way to do this is to create a WorkSheet_calculate sub
in the
code behind worksheet Seged

Or you could check the name of the sheet inside the

Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
if sh.name<"seged" then exit sub
....

Charles
__________________________________________________
The Excel Calculation Site
http://www.decisionmodels.com

"Stefi" wrote in message
...
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













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
Workbook_SheetCalculate twice Stefi Excel Programming 0 May 20th 08 03:25 PM
Workbook_SheetCalculate Events Tom Excel Programming 3 September 3rd 06 11:35 PM
Triggering UDF bhofsetz[_132_] Excel Programming 0 June 29th 06 11:43 PM
triggering macros gvm Excel Programming 1 September 17th 05 04:11 PM
Workbook_SheetCalculate looping Hammer_757[_11_] Excel Programming 2 August 30th 05 08:39 PM


All times are GMT +1. The time now is 07:48 PM.

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"