+ Reply to Thread
Results 1 to 3 of 3

Addin data persistence problem

  1. #1

    Addin data persistence problem

    Hi,

    I am building a excel add-in (VBA) application for risk analysis;
    add-in has a commandbar and userform to allow user to select/enter
    input data. User is allowed to select multiple workbooks simultaneously
    and run data fetch using add-in.
    To my suprise I found that excel allows the variable values in the
    addin be shared across workbook. How can I avoid this from happening,
    is there any work around.

    In the code below (Extracted from addin module), I found that variable
    "I" shares same values across different workbook


    Option Explicit

    Dim CmdItem As CommandBarControl

    Dim i As Long
    Private Sub Pr_LoadDisplay()

    On Error GoTo ERRPART

    MsgBox (i)
    'MsgBox ThisWorkbook.Name
    MsgBox ActiveWorkbook.Name

    Exit Sub
    ERRPART:
    Call ShowErrMessage(Err.Number, Err.Description)
    End Sub

    Private Sub Pr_LoadAdd()
    On Error GoTo ERRPART

    i = i + 1

    Exit Sub
    ERRPART:
    Call ShowErrMessage(Err.Number, Err.Description)
    End Sub


    Thanks,
    PKR


  2. #2
    Tim Williams
    Guest

    Re: Addin data persistence problem

    An add-in is loaded only once and so has the same "properties" (such as the value of a global variable) independent of where it's
    accessed from...

    Tim


    <[email protected]> wrote in message news:[email protected]...
    > Hi,
    >
    > I am building a excel add-in (VBA) application for risk analysis;
    > add-in has a commandbar and userform to allow user to select/enter
    > input data. User is allowed to select multiple workbooks simultaneously
    > and run data fetch using add-in.
    > To my suprise I found that excel allows the variable values in the
    > addin be shared across workbook. How can I avoid this from happening,
    > is there any work around.
    >
    > In the code below (Extracted from addin module), I found that variable
    > "I" shares same values across different workbook
    >
    >
    > Option Explicit
    >
    > Dim CmdItem As CommandBarControl
    >
    > Dim i As Long
    > Private Sub Pr_LoadDisplay()
    >
    > On Error GoTo ERRPART
    >
    > MsgBox (i)
    > 'MsgBox ThisWorkbook.Name
    > MsgBox ActiveWorkbook.Name
    >
    > Exit Sub
    > ERRPART:
    > Call ShowErrMessage(Err.Number, Err.Description)
    > End Sub
    >
    > Private Sub Pr_LoadAdd()
    > On Error GoTo ERRPART
    >
    > i = i + 1
    >
    > Exit Sub
    > ERRPART:
    > Call ShowErrMessage(Err.Number, Err.Description)
    > End Sub
    >
    >
    > Thanks,
    > PKR
    >




  3. #3
    pkr
    Guest

    Re: Addin data persistence problem

    Hi Tim,

    Thanks for the response, but the variables are not public and their
    scope is within the module. I am unable to understand why a variable
    defined within a module in an Addin persist across workbook.

    Can you please help me understand.

    Thanks,
    Pkr
    [email protected] wrote:
    > Hi,
    >
    > I am building a excel add-in (VBA) application for risk analysis;
    > add-in has a commandbar and userform to allow user to select/enter
    > input data. User is allowed to select multiple workbooks simultaneously
    > and run data fetch using add-in.
    > To my suprise I found that excel allows the variable values in the
    > addin be shared across workbook. How can I avoid this from happening,
    > is there any work around.
    >
    > In the code below (Extracted from addin module), I found that variable
    > "I" shares same values across different workbook
    >
    >
    > Option Explicit
    >
    > Dim CmdItem As CommandBarControl
    >
    > Dim i As Long
    > Private Sub Pr_LoadDisplay()
    >
    > On Error GoTo ERRPART
    >
    > MsgBox (i)
    > 'MsgBox ThisWorkbook.Name
    > MsgBox ActiveWorkbook.Name
    >
    > Exit Sub
    > ERRPART:
    > Call ShowErrMessage(Err.Number, Err.Description)
    > End Sub
    >
    > Private Sub Pr_LoadAdd()
    > On Error GoTo ERRPART
    >
    > i = i + 1
    >
    > Exit Sub
    > ERRPART:
    > Call ShowErrMessage(Err.Number, Err.Description)
    > End Sub
    >
    >
    > Thanks,
    > PKR



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1