Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Get UDF to Re-calculate without entering cell

Hi All,

I have the following UDF to check if a file exists:-

Function FileExists(fname) As Boolean

If Dir(fname) < "" Then _

FileExists = True _

Else FileExists = False





End Function



The problem is that it doesn't re-calculate when you press F9. You have to
go into the cell by pressing F2 in order for it to re-calculate.



Adding "Applicaiton.Volatile" doesn't seem to work either.



How do you work around this?



Ta



Andi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Get UDF to Re-calculate without entering cell

Hi

The problem is that Excel doesn't know that the formula should be
're-calculated'. If you add another "volatile" parameter to the function it
will get reclaced every time Excel does a recalc. So changing the function
to:
Function FileExists(fname, CurrentDateTime) As Boolean

If Dir(fname) < "" Then
FileExists = True
Else
FileExists = False
End If

End Function

and then calling it as =FileExists("c:\somefile.txt",NOW())

causes it to check for the file every time something in the workbook has
been changed.

Alternatively, you could look into the OnTime method of the Application
object which lets you schedule when code gets run. Your code would need to
get called from an event or a button initially but it would then schedule
iteslf to run every x seconds/minutes.
--
HTH

Simon


"Andibevan" wrote:

Hi All,

I have the following UDF to check if a file exists:-

Function FileExists(fname) As Boolean

If Dir(fname) < "" Then _

FileExists = True _

Else FileExists = False





End Function



The problem is that it doesn't re-calculate when you press F9. You have to
go into the cell by pressing F2 in order for it to re-calculate.



Adding "Applicaiton.Volatile" doesn't seem to work either.



How do you work around this?



Ta



Andi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Get UDF to Re-calculate without entering cell

Great Simon - I think I will add the now() actually into the code that
should do the same I presume.

"Simon Letten" wrote in message
...
Hi

The problem is that Excel doesn't know that the formula should be
're-calculated'. If you add another "volatile" parameter to the function

it
will get reclaced every time Excel does a recalc. So changing the

function
to:
Function FileExists(fname, CurrentDateTime) As Boolean

If Dir(fname) < "" Then
FileExists = True
Else
FileExists = False
End If

End Function

and then calling it as =FileExists("c:\somefile.txt",NOW())

causes it to check for the file every time something in the workbook has
been changed.

Alternatively, you could look into the OnTime method of the Application
object which lets you schedule when code gets run. Your code would need

to
get called from an event or a button initially but it would then schedule
iteslf to run every x seconds/minutes.
--
HTH

Simon


"Andibevan" wrote:

Hi All,

I have the following UDF to check if a file exists:-

Function FileExists(fname) As Boolean

If Dir(fname) < "" Then _

FileExists = True _

Else FileExists = False





End Function



The problem is that it doesn't re-calculate when you press F9. You have

to
go into the cell by pressing F2 in order for it to re-calculate.



Adding "Applicaiton.Volatile" doesn't seem to work either.



How do you work around this?



Ta



Andi





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Get UDF to Re-calculate without entering cell

I think you'll find that it needs to get passed as a parameter to the
function so that Excel knows it needs to call the function as part of the
recalculation. Just putting a call to the Now() function inside the
function's VBAS code won't tell Excel that the code needs to get run in the
first place.
--

Simon


"Andibevan" wrote:

Great Simon - I think I will add the now() actually into the code that
should do the same I presume.

"Simon Letten" wrote in message
...
Hi

The problem is that Excel doesn't know that the formula should be
're-calculated'. If you add another "volatile" parameter to the function

it
will get reclaced every time Excel does a recalc. So changing the

function
to:
Function FileExists(fname, CurrentDateTime) As Boolean

If Dir(fname) < "" Then
FileExists = True
Else
FileExists = False
End If

End Function

and then calling it as =FileExists("c:\somefile.txt",NOW())

causes it to check for the file every time something in the workbook has
been changed.

Alternatively, you could look into the OnTime method of the Application
object which lets you schedule when code gets run. Your code would need

to
get called from an event or a button initially but it would then schedule
iteslf to run every x seconds/minutes.
--
HTH

Simon


"Andibevan" wrote:

Hi All,

I have the following UDF to check if a file exists:-

Function FileExists(fname) As Boolean

If Dir(fname) < "" Then _

FileExists = True _

Else FileExists = False





End Function



The problem is that it doesn't re-calculate when you press F9. You have

to
go into the cell by pressing F2 in order for it to re-calculate.



Adding "Applicaiton.Volatile" doesn't seem to work either.



How do you work around this?



Ta



Andi






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Get UDF to Re-calculate without entering cell

Simon - My approach does seem to have worked. It does only seem to work
when you press F9 to re-calculate. Doesn't work if you sent calculation to
automatic

"Simon Letten" wrote in message
...
I think you'll find that it needs to get passed as a parameter to the
function so that Excel knows it needs to call the function as part of the
recalculation. Just putting a call to the Now() function inside the
function's VBAS code won't tell Excel that the code needs to get run in

the
first place.
--

Simon


"Andibevan" wrote:

Great Simon - I think I will add the now() actually into the code that
should do the same I presume.

"Simon Letten" wrote in message
...
Hi

The problem is that Excel doesn't know that the formula should be
're-calculated'. If you add another "volatile" parameter to the

function
it
will get reclaced every time Excel does a recalc. So changing the

function
to:
Function FileExists(fname, CurrentDateTime) As Boolean

If Dir(fname) < "" Then
FileExists = True
Else
FileExists = False
End If

End Function

and then calling it as =FileExists("c:\somefile.txt",NOW())

causes it to check for the file every time something in the workbook

has
been changed.

Alternatively, you could look into the OnTime method of the

Application
object which lets you schedule when code gets run. Your code would

need
to
get called from an event or a button initially but it would then

schedule
iteslf to run every x seconds/minutes.
--
HTH

Simon


"Andibevan" wrote:

Hi All,

I have the following UDF to check if a file exists:-

Function FileExists(fname) As Boolean

If Dir(fname) < "" Then _

FileExists = True _

Else FileExists = False





End Function



The problem is that it doesn't re-calculate when you press F9. You

have
to
go into the cell by pressing F2 in order for it to re-calculate.



Adding "Applicaiton.Volatile" doesn't seem to work either.



How do you work around this?



Ta



Andi










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
Entering digits in a cell with numbers already inside cell [email protected] Excel Worksheet Functions 4 August 18th 08 10:34 PM
Entering value in the cell Ridhi Excel Discussion (Misc queries) 1 April 24th 08 09:23 AM
after entering a text in one cell, next cell should disp the entd Sridhar Excel Discussion (Misc queries) 1 August 17th 07 02:18 AM
How do you do hard returns in 1 cell? entering address in 1 cell Jenn Excel Discussion (Misc queries) 2 June 18th 07 03:28 PM
How do I calculate the hours spent on a project by entering a sta. joeh Excel Worksheet Functions 4 November 2nd 04 06:39 PM


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