Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,
Could someone help me with this code?

VB
Dim cmdBar As Microsoft.Office.Core.CommandBarControl
Dim cmdBarButton As Microsoft.Office.Core.CommandBarButton

VB
cmdBar = Globals.ThisAddIn.Application.CommandBars("Cell") _
.Controls.Add(Office.MsoControlType.msoControlPopup, , , 1, )

VB
cmdBarButton = TryCast(cmdBar.Controls.add _(Office.MsoControlType.msoControlButton, , , 1, ), Microsoft.Office.Core.CommandBarButton)

This code is working, but however, I don't understand how and why, because there is no Method Controls for cmdBar Object?

cmdBar.Controls
Why is it working and how to make it better?
Thanks in advance.

(This code is not written by myself.)
Posted
Updated 14-Apr-11 22:27pm
v2

If you're using Visual Studio, use Breakpoint in your code to find out what it's doing on each phase of your code.

Check MSDN: http://msdn.microsoft.com/en-us/library/ktf38f66(v=VS.90).aspx[^]
 
Share this answer
 
Comments
Dragan01 15-Apr-11 4:29am    
hi,
cmdBar is created as expected, but my questions is
how can cmdBarButton be created when there no Method Controls for cmdBar available is?
The solution is found on this site here: http://msdn.microsoft.com/en-us/library/microsoft.office.core.commandbar_members(v=office.11).aspx[^].

Controls is not a method but rather a property of CommandBar.

Hope that clears it up for you!

Cheers,

-MRB
 
Share this answer
 
Comments
Dragan01 15-Apr-11 4:55am    
Hello Manfred

That's correct: Controls is a Property, not Method
But exactly there is a Problem:
cmdBar is declared as CommandBarControl, not as CommandBar, why is the code working? Actually, the code should not be working because in CommandBarControl is no Property Control

I can change declaration of cmdBar from CommandBarControl to CommandBar and than I can be sure that the code is sure
Solved:
VB
Dim cmdBar As Microsoft.Office.Core.CommandBarPopup
Dim cmdBarButton As Microsoft.Office.Core.CommandBarButton

VB
cmdBar = TryCast(Globals.ThisAddIn.Application.CommandBars("Cell").Controls.Add(Office.MsoControlType.msoControlPopup, , , , True), Office.CommandBarPopup)

VB
cmdBarButton = TryCast(cmdBar.Controls.add(Office.MsoControlType.msoControlButton, , , 1, ), Microsoft.Office.Core.CommandBarButton)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900