LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default application.volatile activation

C


I built a macro that reads data from a text file and returns a string

value
from it. When the user puts "=MyMacro(xxx)" in a cell, the returned value
will be some string from my text file.


What is xxx? Cell reference, number, text?

When the user ask Excel to
recalculate the workbook (F9 I believe), my macro is not executed. It

will
be executed only if I put "Application.Volatile" as the first line of that
macro. I want the user to be able to trigger a recalculation of all the
cells that use my macro.


Is the text file changing such that you need a recalculation, or is the xxx
changing and it's getting different text from the (static) text file?


Small problem: reading from a file takes a long time. With
Application.Volatile in my macro, any change to any cell in my workbook

will
trigger the execution of my macro for every cell that uses it. If my

macro
in used in 1000 cells, I don't want the user to wait for 1000 file

accesses
each time he writes something in a cell.


In general, you should avoid Volatile. There are some cases where it's
necessary, but often it's used when it shouldn't be. To avoid using it, you
need to pass all of the information that your UDF will need as an argument
to the UDF. That will force a recalc if any of the arguments change.

If some other program is changing the text file, then you can't pass
everything you need and you will probably have to use Volatile. If that's
the case, you may be able to reduce the access times of the text file. For
instance, open your text file for Input the first time the function is
called, but don't close it. Put a test in your function to determine if the
file is still open and skip the opening part on subsequent passes. Then use
the Calculate event (which I think runs after calculation is complete) to
close the text file. I believe that the opening and closing of the text
file is what's taking all the time, not the actual access.

If you post the UDF, someone will be able to tell you how to change your
arguments so that you don't need Volatile. If the text file is changing and
you want to try to hold the file open through the calculation, let me know
and I can walk you through how to do it. Beware that I haven't actually
tested it, so I don't guarantee that it would work or be any faster. But I
think it's worth a look.


--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


 
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
Call Application.Volatile(True) NOT WORKING FARAZ QURESHI Excel Discussion (Misc queries) 1 May 8th 08 04:50 AM
Application.Volatile Not Working Timely FARAZ QURESHI Excel Discussion (Misc queries) 2 March 10th 08 09:52 AM
Application.Volatile not working as expected Richards Excel Discussion (Misc queries) 3 February 3rd 05 12:20 AM
Need for Application.Volatile? Paul Lautman Excel Programming 2 August 19th 04 10:43 PM
Application.Volatile messing up other function itchyII Excel Programming 1 April 1st 04 04:31 PM


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