none
MS Project 2010, adding custom ui using VBA, callback parameters are missing

    Question

  • Hello,

    I've been trying to add a new tab to the ribbon in Microsoft Project 2010 by constructing a ribbonXML string and calling ActiveProject.SetCustomUI(ribbonXML) on Project_Open. Here's what my XML string looks like:

    <mso:customUI onLoad="RibbonLoaded" xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui"> 
       <mso:ribbon startFromScratch="false">
          <mso:tabs>
             <mso:tab id="MppTab" label="MPP" insertBeforeQ="mso:TabFormat">
                <mso:group id="DataGroup" label="Data">
                   <mso:button id="SaveData" 
                               label="Save Data"
                               imageMso="FileSave" 
                               onAction="SaveData"/>
                   <mso:button id="LoadData" 
                               label="Load Data" 
                               imageMso="ImportMoreMenu" 
                               onAction="LoadData"/>
                   <mso:button id="DeleteData" 
                               label="Delete Data" 
                               imageMso="InkEraseMode" 
                               onAction="DeleteData"/>
                   <mso:dropDown id="Scenario_DropDown" 
                                 label="Scenario:"
                                 getItemCount="ScnGetItemCount" 
                                 getItemLabel="ScnGetItemLabel" 
                                 onAction="Filter_Updated" />
                </mso:group>
             </mso:tab>
          </mso:tabs>
       </mso:ribbon>
    </mso:customUI>

    The problem here whenever any of the callbacks fire, all of the parameters that I am expecting to get are either Nothing or Missing. I know this because I made every argument Optional and then checked the values by putting a breakpoint in each function. If I take the Optional argument out, I get the error "Automation error Exception occurred."

    I've seen it posted elsewhere that callbacks don't work for Project 2010 unless you use VSTO, is that the case or am I just doing something wrong here?

    Thanks!

    Monday, April 09, 2012 6:43 PM

Answers

All replies

  • Hi WRB3,

    Thank you for posting.

    I can reproduce the problem on my side and I also found a thread which is the same as yours problem:

    http://social.technet.microsoft.com/Forums/en-US/project2010custprog/thread/005317a3-7682-4fbd-a6b7-9d35ae8d9ff6/

    I referred to this article on MSDN: http://msdn.microsoft.com/en-us/library/ee767705.aspx

    and try to add the parameter to the ToggleManualTasksColor method, then I encountered the same problem.

    So, the workaround should be using VSTO to customize the ribbon. As for using VBA, I will help you report it to our internal portal, our engineers will evaluate it seriously and then decide whether to improve this feature.

    Thank you for your understanding.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Bruce Song Wednesday, April 11, 2012 6:16 AM
    • Marked as answer by WRB3 Wednesday, April 11, 2012 4:57 PM
    Wednesday, April 11, 2012 6:14 AM
  • Thanks for the help Bruce!

    For anyone else that sees this I'd like to propose an alternative solution to people that don't have Visual Studio Professional (need Professional or higher to use VSTO): CommandBars.

    Here's a portion of what I'm working on now, it creates a commandbar and adds a popup menu to it with various submenus (NOTE: The blank spaces are spacers to get controls on other command bars not shown here to line up properly):

    Private Sub BuildFileBar()
        Dim fileBar As Object
        Dim SubMenu As Object
        Dim cmb As Object
        Dim SubMenu1 As Object
        Dim SubMenu2 As Object
        Dim SubMenu3 As Object
        
        On Error Resume Next
        
        Set fileBar = CommandBars.Add(Name:="FileBar", Position:=msoBarTop, Temporary:=True)
        
        Dim fileMenu As Object
        Set fileMenu = CommandBars("FileBar")
        With fileMenu
            .Visible = True
            .Enabled = True
            .Controls.Add(Type:=msoControlButton, before:=1).Caption = "                 "
            .Controls.Add(Type:=msoControlPopup, before:=2).Caption = "Options            "
            
            Set cmb = fileMenu.Controls("                 ")
            With cmb
                .Visible = True
                .Enabled = False
                .Style = msoButtonCaption
                .OnAction = ""
            End With
            
            ' Add Sub-Menu items to the Database popup
            Set fileSubMenu = fileMenu.Controls("Options            ")
            With fileSubMenu
                .TooltipText = "Select for further options"
                .Controls.Add(Type:=msoControlPopup, before:=1).Caption = "New"
                .Controls.Add(Type:=msoControlButton, before:=2).Caption = "Save Data"
                .Controls.Add(Type:=msoControlButton, before:=3).Caption = "Change Database"
                
                'Now add sub-menu items to the New popup
                Set fileSubMenuNew = fileSubMenu.Controls("New")
                With fileSubMenuNew
                    .Controls.Add(Type:=msoControlButton, before:=1).Caption = "Scenario"
                    .Controls("Scenario").FaceId = 5403
                    .Controls("Scenario").OnAction = "SaveNewScenario"
                    .Controls.Add(Type:=msoControlButton, before:=2).Caption = "Revision"
                    .Controls("Revision").FaceId = 5404
                    .Controls("Revision").OnAction = "SaveNewRevision"
                End With
                
                ' Set an action for the save command, put a group separator above it, and set an icon for it
                Set fileSubMenuSave = CommandBars("FileBar").Controls("Options            ").Controls("Save Data")
                With fileSubMenuSave
                    .OnAction = "SaveData"
                    .BeginGroup = True
                    .FaceId = 3
                End With
                
                ' Set an action for the Change Database command and set an icon for it
                Set fileSubMenuLoad = CommandBars("FileBar").Controls("Options            ").Controls("Change Database")
                With fileSubMenuLoad
                    .OnAction = "ChangeDatabase"
                    .FaceId = 643
                End With
            End With
            .Protection = msoBarNoChangeVisible 'Stops the user from deleting the command bar
        End With
    End Sub

    For each new commandbar that you add, you get a new row in the ribbon, for each control you add to a commandbar you get another column. It's more difficult to get things to line up properly than using the ribbon xml, but it works and you don't have to buy anything. As always google is your friend in learning this.

    Oh! In case you are wondering, .FaceId is the field used to pick an icon to display next to the button. There is no official documentation on what the numbers mean, but the best place I've found to look up IDs is here: http://www.outlookexchange.com/articles/toddwalker/BuiltInOLKIcons.asp 

    Hope this helps anyone that needs it!

    -WRB3


    • Edited by WRB3 Wednesday, April 11, 2012 5:13 PM clarified parts of code
    Wednesday, April 11, 2012 5:12 PM
  • :-(

    I face to this bug too...

    It is really boring as in other hand I have to make a stand-alone Project file (some users might have no access right to the intranet network) with a kind of dynamic Ribbon...

    (I think that I will have to use CommandBars even they are less advanced than Ribbon :-/ )

    [Version : Virtualized MS-Project 2010]

    Friday, June 01, 2012 2:56 PM
  • I share the same frustration. [MS-Project 2010]
    I hope this is corrected.
    It often appears MS-Project is short-changed when it comes to VBA. (Take the lack of status-bar update as another example. Sure it is implimented differently between Excel and Access - but at least it can be done).

    Thursday, September 20, 2012 4:57 PM
  • Were you ever able to make your CommandBars persist? After using VBA to add CommandBars to Project 2010 or Project 2013, if I close and reopen the application, the Add-In's ribbon tab is no longer carrying the CommandBars I added through VBA (which I confirmed by running some VBA code that lists all known CommandBars).

    Mike Oliver, PMP

    Thursday, March 13, 2014 4:33 PM