PC Review


Reply
Thread Tools Rate Thread

How to create separate instance of Add-in for new Workbook?

 
 
aeroshanks@gmail.com
Guest
Posts: n/a
 
      14th Nov 2006
Hi,

VBA version: 6.0.
OS: Win 2000

I have an Add-in which uses XML. The add-in has different user forms to
manipulate the XML data. Assume I have just one Workbook open (WB_1).
Now when I create a new Workbook (WB_2), WB_2 uses the SAME instance of
the add-in.

That means if I make some changes in a user form in WB_1's Add-in,
these changes are reflected in the same user form opened from WB_2's
Add-in.

1. Why is there a same copy of the Add-in for both Workbooks??
2. How can I prevent this from happening? I would like WB_1 and WB_2 to
have their own respective copies of my add-in.

(Instead of creating WB_2, had I opened a new instance of Excel itself,
there's no such problem. WB_1 in the first instance of Excel is totally
independent of the workbook in the second instance of Excel.)

Thanks in advance,
Shankar

 
Reply With Quote
 
 
 
 
Mike Woodhouse
Guest
Posts: n/a
 
      14th Nov 2006


On Nov 14, 7:11 am, aerosha...@gmail.com wrote:
> Hi,
>
> VBA version: 6.0.
> OS: Win 2000
>
> I have an Add-in which uses XML. The add-in has different user forms to
> manipulate the XML data. Assume I have just one Workbook open (WB_1).
> Now when I create a new Workbook (WB_2), WB_2 uses the SAME instance of
> the add-in.


That looks about right.

> That means if I make some changes in a user form in WB_1's Add-in,
> these changes are reflected in the same user form opened from WB_2's
> Add-in.


Correct.

> 1. Why is there a same copy of the Add-in for both Workbooks??


Because Add-ins apply to the instance of Excel, not to Workbooks. I
imagine this is by design.

> 2. How can I prevent this from happening? I would like WB_1 and WB_2 to
> have their own respective copies of my add-in.


Move all the workbook-specific data into a class (representing the
"state"), then maintain a separate instance of the class for each
workbook as necessary. I would look at keeping a Collection of such
objects, keyed by Workbook.Name, so the add-in can ask for the correct
state object for the workbook.

>
> (Instead of creating WB_2, had I opened a new instance of Excel itself,
> there's no such problem. WB_1 in the first instance of Excel is totally
> independent of the workbook in the second instance of Excel.)


Well, yes. Each instance of Excel has its own process space into which
the add-in has loaded.

HTH,

Mike

 
Reply With Quote
 
aeroshanks@gmail.com
Guest
Posts: n/a
 
      15th Nov 2006
Thanks, Mike.
I'll try out what you've said and see if that solves my problem.
Shankar


Mike Woodhouse wrote:
> On Nov 14, 7:11 am, aerosha...@gmail.com wrote:
> > Hi,
> >
> > VBA version: 6.0.
> > OS: Win 2000
> >
> > I have an Add-in which uses XML. The add-in has different user forms to
> > manipulate the XML data. Assume I have just one Workbook open (WB_1).
> > Now when I create a new Workbook (WB_2), WB_2 uses the SAME instance of
> > the add-in.

>
> That looks about right.
>
> > That means if I make some changes in a user form in WB_1's Add-in,
> > these changes are reflected in the same user form opened from WB_2's
> > Add-in.

>
> Correct.
>
> > 1. Why is there a same copy of the Add-in for both Workbooks??

>
> Because Add-ins apply to the instance of Excel, not to Workbooks. I
> imagine this is by design.
>
> > 2. How can I prevent this from happening? I would like WB_1 and WB_2 to
> > have their own respective copies of my add-in.

>
> Move all the workbook-specific data into a class (representing the
> "state"), then maintain a separate instance of the class for each
> workbook as necessary. I would look at keeping a Collection of such
> objects, keyed by Workbook.Name, so the add-in can ask for the correct
> state object for the workbook.
>
> >
> > (Instead of creating WB_2, had I opened a new instance of Excel itself,
> > there's no such problem. WB_1 in the first instance of Excel is totally
> > independent of the workbook in the second instance of Excel.)

>
> Well, yes. Each instance of Excel has its own process space into which
> the add-in has loaded.
>
> HTH,
>
> Mike


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create 2 separate tabs in my workbook? Valerie Microsoft Excel Misc 5 20th Jul 2009 05:31 PM
Switch to Excel workbook in a separate instance of Excel Maverick Microsoft Excel Programming 3 11th Nov 2008 09:22 PM
accessing a class instance from a separate class running in a separate thread titan nyquist Microsoft C# .NET 12 10th Apr 2007 12:27 PM
Create pivottable in separate workbook with ptcache =?Utf-8?B?TWFydGluIExvcw==?= Microsoft Excel Programming 0 6th Oct 2005 12:24 PM
create a separate list from checked items only in a workbook =?Utf-8?B?Qm9iIFdvb2xiZXJ0?= Microsoft Excel Misc 2 21st Oct 2004 02:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:41 AM.