~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
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
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.
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.
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!
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.
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
Sorry, should have said DocumentClose event.
MD
Ayup, that is also how I encountered the problem several years ago.Originally Posted by TonyJollans
My recollection is that I had tested that hypothesis several years ago.Originally Posted by Tommy
Temporary = False is the default so explicitly specifying it shouldn't make any difference. If memory serves, there used to be a problem with Temporary=True not working properly, but I think that's now fixed.
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
I tested and got 5+ commandbars. I saved changes. I opened Normal.dot and deleted the commandbars. I then changed the Temporary = False to Temporary = True. I now do not get duplicates of the commandbars I just get 1. What am I missing?
Hey, Tommy. Just to be clear, in which version are you testing?
~Anne Troy
I sometimes specify certain defaults as that makes the code clearer.Originally Posted by TonyJollans
In addition, specifying the defaults eliminates bugs due to MSFT changing defaults from version to version, rarely done, but it'd cheap protection.
Howard,
MS Bugs - surely not!!
Tommy,
Temporary=True, if it works, means that the toolbars never get saved, no matter how many there are
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