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

BizBoy

Board Regular
Joined
Jul 26, 2012
Messages
116
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
Joined
Jan 11, 2009
Messages
1,170
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
Joined
Jul 26, 2012
Messages
116
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:
Option Compare Database
Sub Test()
Dim MyOrig As Object
Set MyOrig = CommandBars("Menu Bar")
Dim MyMAIN As Object
Set MyMAIN = Application.CommandBars("MenuBar")
Dim MyObj As Object
Set MyObj =Application.CommandBars("Menu Bar")

End Sub
 
Last edited by a moderator:

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
1,742
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
Joined
Jul 26, 2012
Messages
116
Hi Micron sir, thanks a lot for the help. Have a nice day ahead. :)
 

BizBoy

Board Regular
Joined
Jul 26, 2012
Messages
116
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
Joined
Mar 2, 2007
Messages
16,510
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).
 

BizBoy

Board Regular
Joined
Jul 26, 2012
Messages
116
Hi,

Continuing with my original post.
I have following function in my macro.

I am not able to understand what does this function do.
I guess, this function is deleting temp variables but not sure about this.

If I skip below function from my code, will it affect my output.

Or do I need to write it in other way so running this code in Office365 won't affect this function.
Can anyone please help me in this.

Please see below code for your reference. MyProject is declared as in the main module.

VBA Code:
Option Compare Database
Private Function MyFunction()
    Dim MyObject As Object
    Set MyObject = CommandBars("Menu Bar")
    
    On Error Resume Next
    MyObject.Controls("Hel&p for " & TempVars!MyProject).Delete
    Set MyObject = Nothing
End Function
 

Forum statistics

Threads
1,077,911
Messages
5,337,115
Members
399,127
Latest member
GioGR

Some videos you may like

This Week's Hot Topics

Top