What would be the alternative for 'Office.CommandBar' in Office 365 for MS Access

BizBoy

Board Regular
Hi,

I have below lines in my code.

Dim MyOrig As Office.CommandBar
Set MyOrig = CommandBars("Menu Bar")

Dim MyMAIN As CommandBar
Set MyMAIN = CommandBars.ActiveMenuBar

What would be the alternative for 'Office.CommandBar' in Office 365 for MS Access.
This code is written in older version of Access and I need to make it work in Office 365.

I am pretty blank in this scenario, kindly pardon my ignorance.
Can anyone please help me in this.
 
Last edited:

james_lankford

Well-known Member
according to this

https://docs.microsoft.com/en-us/office/vba/library-reference/concepts/overview-of-the-office-fluent-ribbon

it seems like it should still work

[h=2]Existing solutions[/h][FONT=&quot]In versions of Office previous to Office 2007, developers used the CommandBars object model to create the Visual Basic code that modified the UI. In Office, this legacy code continues to work in most cases without modification. However, changes made to toolbars in Office 2003 now appear on an Add-Ins tab in Office.[/FONT]
here's more examples of the CommandBar code

https://docs.microsoft.com/en-us/office/vba/api/office.commandbar

https://docs.microsoft.com/en-us/office/vba/api/office.commandbar.controls

and at the bottom of that very first link is a link to the new way of doing it, but I haven't tried it

https://docs.microsoft.com/en-us/previous-versions/office/developer/office-2010/ff863131(v=office.14)
 

BizBoy

Board Regular
Hi,
I tried below code in both Office 365 and Access 2010.
I was not able to see any difference or bug in any of the environment for this code.

Kindly pardon my ignorance, am new to Access and from Excel background.

If this code is working fine in both versions, what can go wrong here.
I am told that these kind of code lines will not work in Office365 environment.

I tried doing running this code by doing F8. And it ran without any bug.

Hence I assumed code is running without any issues in both the versions.
Am I correct. Can anyone please help me in this.

Code:
[FONT=Calibri][COLOR=#000000]Option Compare Database[/COLOR][/FONT]
[FONT=Calibri][COLOR=#000000]Sub Test()[/COLOR][/FONT]
[FONT=Calibri][COLOR=#000000]Dim MyOrig As Object[/COLOR][/FONT]
[FONT=Calibri][COLOR=#000000]Set MyOrig = CommandBars("Menu Bar")[/COLOR][/FONT]
[FONT=Calibri][COLOR=#000000]Dim MyMAIN As Object[/COLOR][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]    [FONT=Calibri]Set MyMAIN = Application.CommandBars("MenuBar")[/FONT]
[FONT=Calibri]Dim MyObj As Object[/FONT]
[/COLOR][/SIZE][SIZE=3][COLOR=#000000]Set MyObj =Application.CommandBars("Menu Bar")[/COLOR][/SIZE][/FONT]

[FONT=Calibri][COLOR=#000000]End Sub[/COLOR][/FONT]
 
Last edited:

Micron

Well-known Member
Did you look for this old toolbar or menu in the Quick Access area of the ribbon? If I recall, that's where it will show up but it's not obvious.
Can't recall what happens if you hide the main ribbon; i.e. does it hide the QA menu as well, thus your old tb is not available? Or does it make your tb appear like it did in older versions?

You might want to explore the idea of converting your old tb to the updated ribbon.
 
Last edited:

BizBoy

Board Regular
Hi,
Stuck at the above mentioned query.
I ran the code in both the Office 365 and 2010.

I did not face any bug. I was not able to see any difference in the file menu in both the versions.
If I select 'Org_1' and check in Quick Watch, I can not see any value in both the versions.

Not able to understand if this code is working in Office365.
Please pardon my ignorance, but am not sure what ideal output should be for this code.
Since I am not getting any bug while running these lines, not able to determine if there is any issue.

What should I check after running these lines in 2010 that I should reconcile in Office365.
As advised, I tried checking Quick Access Area of the ribbon, but was not able to locate this either.

Only information I have is, this code was written in earlier versions of Access and won't work in Office365.
So am required to edit this code but at present am not able understand how to proceed on this.

Can anyone please help me in this.


VBA Code:
Option Compare Database
Sub Dummy_Code()
    Dim Org_1 As Object
    Set Org_1 = CommandBars("Menu Bar")
  
    Dim MyMain As Object
    Set MyMain = Application.CommandBars("Menu Bar")
  
    Dim MyLong As Object
    Set MyLong = Application.CommandBars("Menu Bar")
  
    Dim MyShortcut As Object
    Dim MyIter As Long
    MyIter = 1
    Set MyShortcut = Application.CommandBars(MyIter)
End Sub
 

xenou

MrExcel MVP, Moderator
This code doesn't do anything. So you shouldn't expect anything to happen even if it runs successfully (except set some variables and then not do anything with them).
 

Some videos you may like

This Week's Hot Topics

Top