none
Type CommandBar is not defined RRS feed

  • Question

  • I've referenced Microsoft Office 12.0 Object Library.  Not Microsoft Word 12.0 Object Library.  The latter being mistaken for the former seems to be a common error.  My reference is definitely set to "Office".  Naturally, Intellisense is void of any events, methods or properties beginning with "Command".  Is there some namespace I need to Import (vb)?  That's what it acts like.

    If anyone can help, I'd be very grateful.

    Thursday, October 10, 2013 7:35 PM

Answers

  • Hans, it looks like I solved it.  There was a reference called "office" in the reference list.  When I removed it, that eliminated the "ambiguous" error.   Ticking the Microsoft.Office.Core namespace fixed the OP. 

    Thanks for the help.

    Cheers

    • Marked as answer by Chipwitch2 Thursday, October 10, 2013 10:23 PM
    Thursday, October 10, 2013 10:23 PM

All replies

  • You can use code like this:

        Dim cbr As CommandBar
        Dim cbb As CommandBarButton
        Set cbr = Application.CommandBars.Add(Name:="My Toolbar", Temporary:=True)
        cbr.Visible = True
        Set cbb = cbr.Controls.Add(Type:=msoControlButton)
        With cbb
            .Style = msoButtonCaption
            .Caption = "My Button"
            .OnAction = "MyMacro"
        End With


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, October 10, 2013 7:46 PM
  • Thanks for the reply, Hans.  But, the problem is CommandBar and CommandBarButton are not recognized by the IDE (Intellisense).  It chokes on the Dim statements saying that the Type is not defined.
    Thursday, October 10, 2013 8:51 PM
  • If - as you wrote - you have set a reference to the Microsoft Office 12.0 Object Library, CommandBar and CommandBarButton should be recognized. The only explanation I can think of for them not being recognized is that there is something wrong with the reference. Try clearing it in the References dialog. Click OK, then reopen the dialog and set the reference again.

    You might try

        Dim cbr As Office.CommandBar
        Dim cbb As Office.CommandBarButton

    but that really shouldn't be necessary.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Thursday, October 10, 2013 9:46 PM
  • I just went into the references to check for about the 20th time and to take a screen shot as evidence.  It's been a while since I've done any programming and like I said in the OP, I wasn't sure what namespace this CommandBar was in.  That info was absent on every site I went to. Anyway, I went through the "import namespaces" under the references list and started ticking some of the namespaces there. 


    One bit of success... ticking Microsoft.Office.Core  got rid of the error.  However, it was replaced by "Error    1    'CommandBar' is ambiguous in the namespace 'Microsoft.Office.Core'. "

    I checked for redundant references and namespaces, but admittedly, my lack of proficiency limits me to only catching the obvious.

    Thursday, October 10, 2013 10:16 PM
  • Hans, it looks like I solved it.  There was a reference called "office" in the reference list.  When I removed it, that eliminated the "ambiguous" error.   Ticking the Microsoft.Office.Core namespace fixed the OP. 

    Thanks for the help.

    Cheers

    • Marked as answer by Chipwitch2 Thursday, October 10, 2013 10:23 PM
    Thursday, October 10, 2013 10:23 PM