~Anne Troy
I tried with Word 2002 and could not duplicate the issue.
Hi Anne,
I couldn't duplicate the exact problem as described either, but I did get a duplicate once....See if this fixes it on yours (it appears it did on mine)
John
Edit: The problem appears to be that the single procedure was deleting the toolbar and then immediately adding the toolbar back in, and there was also a duplication of one piece of code. I deleted the duplication and split delete and add into two separate procedures (done on Office 2000 Premium edition)
Hi,
I couldn't replicate it either (Word 2000). I agree the delete and remake are too close together and this may cause the problem. Things don't always happen in "real life" as they do in stepping through a macro. I would allocate Delete Tooolbar to a DocumentOpen event in the template
MD
Yep, that's definitely it! I went back in and ran the delete/remake as a single procedure again, followed instructions, and ended up with THREE toolbars. It seems that there is simply not always enough TIME for the toolbar to be successfully deleted before the code creating a new one is activated.Originally Posted by mdmackillop
Even slowing it down by simply changing "debug.print" to "MsgBox" slows everything down enough for it to run correctly (without duplicated toolbars) - a simple pause or some other operation should also do the trick
In the general case that won't work as one does not always easily know WHEN the toolbar will need to be deleted.Originally Posted by mdmackillop
The posted example was constructed to exacerbate the problem.
I can replicate this (2000 w/o SP1 or SP2 at the moment).
I am not comfortable with the explanation given though. It is perfectly reasonable (and not uncommon) to delete an object (for safety's sake) before (re-)creating it and I've never heard of this happening before.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
The problem was not discovered by moi alone, a number of others also reported/confirmed the problem.
It's clearly a timing issue, Word has this worse than the other Office apps, so a "general" solution ain't so easy. Users would not be happy of macros included long wait loops.
I wonder if the problem is going to get worse when Office is .NET-ized as garbage collection is very different in .NET. Wow, think of all the new bugs we will have to investigate! Something to look forward too!
I think this is the problem.
tempORary:=False
When the tool bar is created it sets the temporary flag to false. I don't know this but Word may place the information (the toolbar) in a seperate area for permanent tollbars vs temp toolbars.
My recollection is that I had tested that hypothesis several years ago.Originally Posted by Tommy
Hi Tony,
I had a similar problem here.
Solved: Find text in Excel workbook
My code created added a worksheet and then tried to add code to that sheet. Although it worked fine in "step through", in practice, the sheet was not added until the macro had completed, and the AddCode was "missed"
MD
Changing the timing, by splitting the code, does not always work.
Tried that many times, not always successful.
In the real applications in which I have encountered the problem, the code was not always so close together, so there's no simple timing solution.
I constructed the example to exacerbate the timing aspect.
May not be relevant but, in playing with this, I ended up at one point with three copies of the toolbar - all invisible. I deleted them all through Tools > Customize and closed Word and restarted and they were all still there.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Ayup, that is also how I encountered the problem several years ago.Originally Posted by TonyJollans
Had the same thing...I still think the problem is timing, but exacerbated by the fact that there is actually no macro/module in the workbook being used. The macro is in the template and is being referenced by the workbook and what happens in one is not neccessarily being duplicated in the other at the same time (this is instanced by the fact that you can rename, change, and save, the workbook but on exiting the book you will then be asked if you want to save the template)Originally Posted by TonyJollans
We need to stick to Word in this thread, Excel is usually not as misbehaving as Word.Originally Posted by johnske
Re: My last post (quoted above) anyone else wanna try this?Originally Posted by johnske
1) export the module from the template
2) move the template to the recycle bin
3) now import the module into the document
4) goto tools/references and untick any reference to the template
5) disable CustomizationContext = NormalTemplate by putting an apostrophe in front of it
6) save...
Now run the macro (delete & instant remake) and see if you get any duplications
I did and couldn't get any....
Is not your code using Temporary=True?Originally Posted by johnske
If so, that ignores the problem, and is not a solution.
Sorry, nope...I'm using Temporary=FalseOriginally Posted by Howard Kaikow
Sorry, should have said DocumentClose event.
MD