MS Office Forum / Word / Programming / May 2006
Popup controls in CommandBar are disabled although enabled by VBA
|
|
Thread rating:  |
Sheila - 03 May 2006 15:51 GMT This is the base situation:
I have a couple of document templates that all depend on the same Add-In. Every template shows the same toolbar that I have manually created. Some of the controls manually added to this toolbar are of type msoControlPopup, some of type msoControlButton.
In the Add-In, I am customizing the manually created toolbar by means of VBA: At the "new" and the "open" event of the documents, I am first removing all controls belonging to the main popup controls and then adding them again to the popup controls. Again, some of these sub-controls are of type msoControlPopup.
This is the problem:
When I am creating a new document or opening an existing one, everything is fine.
When I am creating or opening a second or a third or a ... document, the popup controls are disabled (and only the popup controls). Sometimes, only the sub-controls are disabled, sometimes, the main controls are disabled. Unfortunately, this does not happen regularly. I have observed though that the phenomenon ALWAYS occurs when the concerned document does NOT have the same template as the previous one. But it sometimes also occurs when the concerned document DOES have the same template as the previous.
By setting the breakpoint before the code removes the sub-controls, I can see that the main controls already are disabled before the code even touched them.
When I call a MsgBox at the end of the toolbar filling that tells me the enabled state of a certain control, it tells me "True" even if the control is disabled.
What I have tried already (but it did not help), always by means of VBA:
1) Explicitly enabled all popup controls after they are all created. 2) Created two templates with the code of above point 1 (that code normally comes from the Add-In). 3) Checked and re-checked the CustomizationContext (ActiveDocument)
What am I missing here?
Help would be appreciated!
Thanks, Sheila
Charles Kenyon - 03 May 2006 18:01 GMT What happens if you change the customization context to the toolbar container (the template)? Perhaps you can't do that.
 Signature Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
My criminal defense site: http://addbalance.com --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom.
> This is the base situation: > [quoted text clipped - 51 lines] > > Thanks, Sheila Sheila - 03 May 2006 18:25 GMT Good idea, I have tried it right now, but it doesn't help either.
Another information: I have set the breakpoint at the very first line of code, and the popup controls are already disabled before any of my code is executed.
Any other ideas?
Thanks and regards, Sheila
> What happens if you change the customization context to the toolbar > container (the template)? Perhaps you can't do that. [quoted text clipped - 53 lines] > > > > Thanks, Sheila Cindy M -WordMVP- - 04 May 2006 08:31 GMT Hi =?Utf-8?B?U2hlaWxh?=,
> I have a couple of document templates that all depend on the same Add-In. What kind of Addin? A COM-Addin, or a global template Addin? And where is the code stored that is assigned to the controls you're creating and destroying? Finally, which version of Word are we dealing with?
Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
Sheila - 04 May 2006 09:03 GMT Hello Cindy
It is a global template Add-In. The code is stored in the Add-In. (But some of the controls are created manually, not by code, and they are disabled too.) The versions are 2000, 2002 and 2003 (I tested all of them).
I have noticed something else: I created a new document, and its popup controls were disabled again, just as described earlier. But then I closed another document, and this action enabled the controls of the new document. I now tend to believe that this is not a VBA problem but a "customized-toolbar-problem".
What do you think?
Kind regards, Sheila
> Hi =?Utf-8?B?U2hlaWxh?=, > [quoted text clipped - 11 lines] > This reply is posted in the Newsgroup; please post any follow question or > reply in the newsgroup and not by e-mail :-) Cindy M -WordMVP- - 10 May 2006 15:43 GMT Hi =?Utf-8?B?U2hlaWxh?=,
> It is a global template Add-In. > The code is stored in the Add-In. (But some of the controls are created [quoted text clipped - 8 lines] > > What do you think? From the sound of it, if we were talking COM Addin, my first guess would be that you've not set a unique TAG property.
Given that this is a template Addin, my next thought would be CustomizationContext, but you say you've double-checked that. However, I'm not certain I understand all the logic behind what you're doing. My feeling is that we are fighting with where the commandbar things are being saved. You say the toolbar is in a global Addin template, but that the changes you're making are to single documents. I think the problem is that Word can't handle these multiple changes "on-the-fly" like this. You'd probably do better to recreate the entire toolbar in each document, as it's opened. Set the "Temporary" parameter of the toolbar to "True" so that it's destroyed whenever the document is closed.
Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
Sheila - 15 May 2006 17:40 GMT Dear Cindy
The VBA creation of the entire toolbar did the trick -- Thank you very much!
(I'll never do that manually again if I don't have to. It takes longer, and it seems to be less reliable.)
Sheila
> Hi =?Utf-8?B?U2hlaWxh?=, > [quoted text clipped - 31 lines] > This reply is posted in the Newsgroup; please post any follow question or reply > in the newsgroup and not by e-mail :-) Cindy M -WordMVP- - 16 May 2006 14:05 GMT Hi =?Utf-8?B?U2hlaWxh?=,
> The VBA creation of the entire toolbar did the trick -- Thank you very much! > > (I'll never do that manually again if I don't have to. It takes longer, and > it seems to be less reliable.) I'm glad it worked :-)
Manual creation / management of toolbars works fine, as long as things are relatively "static". As soon as you start manipulating a toolbar that's saved in one place with "local changes", things can get tricky because Word may get itself in a tangle keeping track of what should be visible where/when.
So, for example, if you're setting up a template that will be used to create a new document, and want to provide task-specific tools, you can save them in that template - no problem.
OTOH, if you have a global template, as in your situation, and want to provide tools only under certain circumstances, then it's better to create the tools on-the-fly.
Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005) http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
Charles Kenyon - 16 May 2006 14:58 GMT I create my controls manually, but sometimes I turn them on and off with code. First, I create all of my controls in custom toolbars. I may copy them later to a built-in toolbar, but the original control is on a custom toolbar. This is because you can't transfer customized built-in toolbars, but you can transfer custom toolbars.
For me, this means that I have my own Formatting and Standard Toolbars; I don't use the ones that come with Word except as a model for my own.
I enable and make visible certain toolbars on Word startup as the last part of code in a global template's autoexec. Some of those toolbars actually reside in other global templates. I also set their positions so that I find them where I expect to find them.
For me, this enabling and positioning with code is much easier than actually creating the toolbars on the fly. I don't need to create them on the fly because they are the same in every session, just used or not used. In any case, you need to be very cognizant of the customization context, whether creating toolbars manually, repositioning them, or using code.
 Signature Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
My criminal defense site: http://addbalance.com --------- --------- --------- --------- --------- --------- This message is posted to a newsgroup. Please post replies and questions to the newsgroup so that others can learn from my ignorance and your wisdom.
> Dear Cindy > [quoted text clipped - 53 lines] >> reply >> in the newsgroup and not by e-mail :-)
|
|
|