PDA

View Full Version : User Def Function to only act on active workbook



ragingradish
07-03-2008, 10:02 AM
Howdy everyone, I've got a bit of a problem.

I've created a couple of Functions which are saved in a .xla file that gets loaded as Excel starts. So far so good. What the function does is gets the Path of the ActiveWorkbook and then opens another file (belonging to an application called Caseware) in order to retrieve data from it. It works well, except for one thing:

If 2 or more workbooks are open and they have different filepaths, the function will also execute in the Excel workbook that is NOT active and return incorrect information to that inactive workbook.

So my question is this: Is there a way to have these functions run only in the active workbook and ignore any other open workbooks?

Using Excel 2003, SP3 on Windows XP

Bob Phillips
07-03-2008, 10:04 AM
Probably. Can we see the code?

ragingradish
07-03-2008, 10:29 AM
This is it. The Caseware object model will probably be unfamiliar.

Function ACT gets the path value from the function getCwLink(). The end result is to return an account balance from the trial balance stored in the Caseware client file.


Edit: code removed

ragingradish
07-03-2008, 01:04 PM
I think I may have the answer by doing this right before exiting the function:

Sub abortCalc()

Dim wb As Variant
Set wb = Application.ActiveWorkbook
Application.CheckAbort KeepAbort:=wb

End Sub