Navigate to Selected Worksheet via Ribbon Drop-Down

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
I have the following code which seemed to be working fine, and now all the sudden isn't working. It's a dropdown box built into the ribbon, and when selected, calls the following code:

Code:
Option ExplicitDim Rib As IRibbonUI
Private mwkbNavigation As Workbook


Sub getItemCount(control As IRibbonControl, ByRef returnedVal)
    Dim lCount As Long
    Dim wksSheet As Worksheet
    Set mwkbNavigation = ThisWorkbook
    For Each wksSheet In mwkbNavigation.Worksheets
        If wksSheet.Visible = xlSheetVisible Then
            lCount = lCount + 1
        End If
    Next wksSheet
    returnedVal = lCount
End Sub


Sub GetSelectedItemIndexDropDown(control As IRibbonControl, ByRef index)
  index = ActiveSheet.index - 1
End Sub


Sub getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
    If mwkbNavigation.Worksheets(index + 1).Visible = xlSheetVisible Then
        returnedVal = mwkbNavigation.Worksheets(index + 1).Name
    End If
End Sub


Sub onAction(control As IRibbonControl, id As String, index As Integer)
Dim sSheetName As String

sSheetName = mwkbNavigation.Worksheets(index + 1).Name [COLOR=#ff0000][[/COLOR][COLOR=#ff0000]This is where the error occurs....][/COLOR]
mwkbNavigation.Worksheets(sSheetName).Activate


End Sub


Sub Ribbon******(ribbon As IRibbonUI)
    Set Rib = ribbon
End Sub


When I try to run the code, I get a "Run Time Error 91: Object variable or With block variable not set."

I am not sure why all the sudden it doesn't work....

Any thoughts or suggestions?
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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