Consulting

Results 1 to 4 of 4

Thread: User Def Function to only act on active workbook

  1. #1

    Question User Def Function to only act on active workbook

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Probably. Can we see the code?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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
    Last edited by ragingradish; 07-04-2008 at 09:45 AM.

  4. #4
    I think I may have the answer by doing this right before exiting the function:
    [VBA]
    Sub abortCalc()

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

    End Sub
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •