PDA

View Full Version : Activate Ribbon Tab In Excel 2007 2010 *



Excel Fox
04-21-2011, 04:31 PM
One can access the Ribbon by using Commandbars("Ribbon") that will return an IAccessible object. You can access the tabs using the oleacc.dll library which can return an array of other IAccessible objects which are basically the list of all child elements. So the first child of the ribbon would be its tab. Using the IDs (which are strings) of these children objects you can filter in to the next child level which can be menu items etc.

Credit to Tony Jollans, Microsoft Word MVP for the ribbon demo that you can find at www.WordArticles.com (http://www.WordArticles.com)

Here you can download a working example of how to activate a tab in either 2007 or 2010 versions of Excel. Note, for Excel 2010, MS has already incorporated the ActivateTab and ActivateTabMso methods, so one doesn't have to worry about elaborate codes to get the job done. The XML code used is given below



<customUI onLoad="OLUIR" xmlns=http://schemas.microsoft.com/office/2006/01/customui>
<ribbon>
<tabs>
<tab id="tabAUniqueNameIDForMyNewTab" label="My New Tab" insertAfterMso="TabView">
</tab>
</tabs>
</ribbon>
</customUI>

philipb645
01-30-2012, 09:41 PM
I was able to make this work on all the tabs except for the "Add-Ins" and this is the one I'm wanting to display. Is there something I have to do special for the "-" in 'Add-Ins'?

Also I saw you mentioned 2010 had some built in functionality....If I am using 2010 then do I not need all of your code?

Thanks.

Phil


https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg.9xmkXGSciKJ9xonTti2s Ix (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwTUdEgR4bdt6crKXF4AaABAg.9xmkXGSciKJ9xonTti2s Ix)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg.9xnskBhPnmb9xoq3mGxu _b (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgwWw16qBFX39JCRRm54AaABAg.9xnskBhPnmb9xoq3mGxu _b)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9xon1p2ImxO)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg.9xm_ufqOILb9xooIlv5P LY (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgybZfNJd3l4FokX3cV4AaABAg.9xm_ufqOILb9xooIlv5P LY)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgzgWvzV-kvC4TJ8O414AaABAg.9xnFzCj8HRM9y38bzbSqaG)
https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg.9xmt8i0IsEr9y3FT9Y9F eM (https://www.youtube.com/watch?v=XQAIYCT4f8Q&lc=UgyWm8nL7syjhiHtpBF4AaABAg.9xmt8i0IsEr9y3FT9Y9F eM)
https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg.9xhyRrsUUOM9xpn-GDkL3o (https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg.9xhyRrsUUOM9xpn-GDkL3o)
https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg (https://www.youtube.com/watch?v=jTmVtPHtiTg&lc=Ugy_RiNN_kAqUvZ8W994AaABAg)
https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNsaS3Lp1 (https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNsaS3Lp1)
https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgR1EPUkhw (https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgR1EPUkhw)
https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNe_XC-jK (https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNe_XC-jK)
https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNPOdiDuv (https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgNPOdiDuv)
https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgN7AC7wAc (https://www.youtube.com/watch?v=QjEWAJ3d-jw&lc=UgxJLVpwY8fIla7G-pN4AaABAg.9BLeCWVhxdG9wgN7AC7wAc)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

Excel Fox
02-04-2012, 12:08 PM
Phil,

Welcome to Excel Fox

You can simply call the function like so



Sub OLUIR(ribbon As IRibbonUI)

On Error Resume Next
If Val(Application.Version) = 14 Then
ribbon.ActivateTabMso "TabAddIns" ' For Excel 2010
ElseIf Val(Application.Version) = 12 Then
Application.OnTime Now(), "ActivateMyTab" 'For Excel 2007
End If

End Sub

Sub ActivateMyTab()

ActivateTab "Add-Ins"

End Sub

Excel Fox
02-04-2012, 12:10 PM
The code above is written to take care of Excel 2010 also....

However, if you were only using 2010, you wouldn't need the IF condition


Sub OLUIR(ribbon As IRibbonUI)

On Error Resume Next
ribbon.ActivateTab "TabAddIns" ' For Excel 2010

End Sub

philipb645
02-06-2012, 06:44 PM
So do I have to call that sub? I for the live of me can't make the code work you gave me for just 2010. Don't I have to pass in a ribbon?

Excel Fox
02-26-2012, 02:48 AM
Check the attachment...

philipb645
02-27-2012, 08:42 PM
I've attached my sample project. It has a menu which shows on the add-ins tab. With your code, I can't seem to give focus to it. I'm sure I missing something easy.

Rob Kemper
09-28-2012, 03:06 PM
Hello,

5091
This is the example that I tried in Excel 2007.

You asked me to start a new thread but the button to do so is not available. According to manual I do not have the rights probably. I have registered.

If you open the example it creates the custom tab but gets an error 91 because the ReturnElement has value Nothing and cannnot call its method. In my opinion this is caused because GetAccessible does not find the custom tab in the control tree.

Can you look into this example in spite of the fact that I did not create a new Thread?

Thanks

Rob Kemper

Excel Fox
10-05-2012, 11:14 AM
Rob, I tried in quite a few computers, and this is working without any error in all those computers.

flatratte82
01-02-2013, 06:33 PM
Rob, I tried in quite a few computers, and this is working without any error in all those computers.

I can confirm that this example file does not work with excel 2007.
The sub "ActivateTab" is not able to set "PageTabListClient".

Regards

Excel Fox
01-07-2013, 02:34 PM
I tried the Excel 2007 version and it is working fine. For Excel 2010 file, I tried it in Excel 2010 office version and it worked too (I was pretty sure I tested this an appropriate number of times before uploading these two files).

Hope you have the latest Service Pack installed.

flatratte82
01-07-2013, 07:58 PM
My version is:
Microsoft Office Excel 2007 (12.0.6665.5003) SP3 MSO (12.0.6662.5000)

LalitPandey87
02-19-2013, 12:10 PM
Thanks Admin, It really helps. Thanks a lot. :cheers:

anisheco
12-18-2013, 06:21 PM
Hi Admin, I am new to the forum and this is my first post. Please guide me if I am not going according to the forum rules.

I have created a ribbon tab on my file and I want that tab (control id = "TabBT") to be selected once the file is opened. I would be using this file on Excel 2010 and Excel 2013. I tried several ways of doing it like, assigning a keytip and then using sendKeys (did not work). I also tried the solution given in this thread but no result.

Would appreciate any help on this and would like to learn as how do we do it. Let me know if I was not very clear.

Regards,
Anish

anisheco
12-20-2013, 01:52 AM
Thank you very much.. I figured it out by looking at the very first file example you had attached. I am using Andy Pope's Ribbon Editor/Designer and it was not giving any call back option for CustomUI onLoad. I used the CustomUI editor and added that syntax. I worked fine after that.

Regards,
Anish

klimbo123
01-22-2019, 02:55 PM
Hello,

394
This is the example that I tried in Excel Tutuapp (https://dltutuapp.com/) 9apps (https://9apps.ooo/) Showbox (https://showbox.run/) 2007.

....
please the link does not work you can give me another link ??
thanks

DocAElstein
01-22-2019, 05:05 PM
please the link does not work you can give me another link ??
thanks
This ??
"How To Activate A New Ribbon Tab.xlsm" : https://app.box.com/s/h7om86vsnnsync61skxsb5npi8lllck6

Alan

( from post #6 :
"How To Activate A New Ribbon Tab 2010.xlsm" : https://app.box.com/s/ffvd87cvbz2qny3w5encd4hb8is893s4 )




Easily activate ribbon tab by Click the Ribbon Display Options icon on the top-right corner of your document. It is to the left of the Minimize icon. In the menu that opens, click Show Tabs and Commands to show the Ribbon with all tabs and full commands.