VBA to go to Home Tab

What is the name of your "home tab"?

I have assumed "home", but you need to change appropriately.
it's 'Home' only.

Just to avoid any ambiguity 👇

Screenshot 2025-02-16 102848.png


Thanks a lot 🙏
 
Upvote 0

VBA Code:
Option Explicit

Public Function ActivateRibbonTab(ByVal strTabName As String) As Boolean
    
    Dim UIA                              As UIAutomationClient.CUIAutomation
    Dim UIElement                        As UIAutomationClient.IUIAutomationElement
    Dim Condition                        As UIAutomationClient.IUIAutomationCondition
    Dim ToolsTab                         As UIAutomationClient.IUIAutomationElement
    Dim LegacyIAccessiblePattern         As UIAutomationClient.IUIAutomationLegacyIAccessiblePattern
    
    Set UIA = New CUIAutomation
    Set UIElement = UIA.ElementFromHandle(ByVal Application.Hwnd)
    
    If Not (UIElement Is Nothing) Then
        Set Condition = UIA.CreateAndCondition(UIA.CreatePropertyCondition(UIA_NamePropertyId, ByVal strTabName), _
        UIA.CreatePropertyCondition(UIA_ClassNamePropertyId, "NetUIRibbonTab"))
        Set ToolsTab = UIElement.FindFirst(TreeScope_Subtree, Condition)
        If Not (ToolsTab Is Nothing) Then
            Set LegacyIAccessiblePattern = ToolsTab.GetCurrentPattern(UIA_LegacyIAccessiblePatternId)
            LegacyIAccessiblePattern.DoDefaultAction
            ActivateRibbonTab = True
        End If
    End If

End Function

Then run this:
ActivateRibbonTab "Home"

This is language dependent, though.
 
Upvote 0

Forum statistics

Threads
1,226,795
Messages
6,193,046
Members
453,772
Latest member
aastupin

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