Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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


wrote in message ups.com...
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
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
User Defined Forumla and persistence Eros Pedrini[_2_] Excel Programming 1 November 19th 04 04:14 PM
Addin problem boopesh Excel Programming 1 December 11th 03 12:56 PM
Class and object persistence James Neumann[_2_] Excel Programming 0 September 9th 03 03:48 PM


All times are GMT +1. The time now is 07:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"