procedure continuously being called
I am using "application.volatile" in a function procedure in order for the
procedure to be called. The function does not refer to a cell value and
therefore won't be called unless .volatile is used.
Basically, what I am trying to do is to set the worksheet background to a
particular .gif file when the workbook is changed to/from "read-only". Since
my workbook uses DDE links, it calculates continuously. Therefore, the
function is called continuously, slows the workbook down and makes the screen
flicker as it continuously sets the background picture.
I have separated this task into the following two functions to try to keep
the function that sets the background (function #2) to only run when the
read-only status (function #1) changes, but it still does it continuously:
#1
Function read_only_status() As Byte
Application.Volatile True
If ActiveWorkbook.ReadOnly = True Then
read_only_status = 1
End If
If ActiveWorkbook.ReadOnly = False Then
read_only_status = 2
End If
End Function
#2
Function set_background(status As Byte)
If status = 1 Then
Worksheets("a.book").SetBackgroundPicture "c:watermark.gif"
End If
If status = 2 Then
Worksheets("a.book").SetBackgroundPicture Delete
End If
End Function
Any suggestions as to how I can get this procedure to NOT run continuously
and still actually work?? Thank you.
|