Automatically going to a custom Ribbon tab upon start up

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Having a bit of trouble with this one. When I load the application and manually hit 'Alt' + "Y3" + 'Alt' it works perfectly. It seems it doesn't like it when I place the code in the Workbook_Open sub-routine.

VBA Code:
Private Sub Workbook_Open()

Application.SendKeys "%Y3%"   'Alt + Y3 + Alt key

End Sub

It gives me an odd error saying "The cell or chart you're trying to change is on a protected sheet. To make a change, unprotected the sheet. You might be requested to enter a password"

Very odd, I can do it manually but not programmatically. Any thoughts?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You'd be better off using the ribbon's onLoad callback so that you can use the iribbonui.activatetab method.
 
Upvote 0
Upvote 0
You might want to use OnTime to call a separate routine that activates the tab.
 
Upvote 0
Tried it but am getting an error prompt "Invalid procedure call or argument"

XML
<customUI onLoad="RibbonOnLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">


VBA
VBA Code:
Public Rib As IRibbonUI

Sub RibbonOnLoad(ribbon As IRibbonUI)

Set Rib = ribbon
Application.OnTime Now + TimeValue("00:00:05"), Procedure:="LoadTab"

End Sub

Sub LoadTab()

Rib.ActivateTab "My custom ribbon name" 'Name of the tab to activate  <----------- Error happens here! "Invalid procedure call or argument"

End Sub
 
Upvote 0
Which module is that code in?
 
Upvote 0
Sounds like you have the wrong name for the tab
 
Upvote 0
I was using the tab "label" instead of the tab "id". Duh!!! Thanks for sniffing that one out. Works perfectly now.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top