Macro Excel - Activex Button that goes on a hidden sheet

mldaigle1
mldaigle1 used Ask the Experts™
on
Hello,

I have hidden all the sheets in a workbook except Sheet1, on which I have multiple Activex buttons.  

When I click on Button1, it goes on the sheet2 and on sheet2 i have a "back" button that once i click on it, will bring me back to sheet1
I have 10 buttons like this.

Since I have hide all the sheets except Sheet1, i really don't know how I can activate a sheet,  It does give me an error message.

Any suggestion how I can resolve that issue (work with hidden sheets but been able to access it when i press an activex button)

Thanks in advance,

/mld
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
byundtMechanical Engineer
Most Valuable Expert 2013
Top Expert 2013

Commented:
Are you saying that you want to activate a hidden worksheet? If so, you must first make it visible, then you can activate it. The following sub will make a hidden worksheet visible and activate it. If run again, it will make the worksheet hidden. If you used a Forms control command button (instead of ActiveX), you could write one sub like this one, and call it from buttons on both the Master worksheet and the one being hidden/unhidden.
Sub ToggleSheetVisibility()
Dim ws As Worksheet
With Worksheets("Sheet2")
    If .Visible = xlSheetVisible Then
        .Visible = xlSheetVeryHidden
    Else
        .Visible = xlSheetVisible
        .Activate
    End If
End With
End Sub

Open in new window


If your problem is that you are using recorded macros and they are activating worksheets and selecting cells, then the better solution may be to rewrite the macro so you don't need to activate or select anything. You can then keep hidden worksheets hidden, yet still let your macro run.
Mechanical Engineer
Most Valuable Expert 2013
Top Expert 2013
Commented:
I revised the previous code so you could have one sub that serves all the buttons on the Master worksheet as well as the return buttons on the hidden worksheets. It's a lot easier to create and maintain one sub rather than the 20 that you would need with the ActiveX controls in your original plan.

The code assumes that the caption on the buttons either is the name or ends with the name of the worksheet that you want to activate. The code should be installed in a regular module sheet (not in the code pane for a worksheet). You must also use either shapes or Forms controls as command buttons rather than ActiveX controls. Finally, the code assumes that worksheet names do not include space characters, and that the Master worksheet is called Master.

The sample workbook shows how it might work. There are seven worksheets. Worksheet Master will always be visible, but Sheet2, Sheet3, Sheet4, Sheet5, Sheet6 and Sheet7 will be hidden unless they are the active sheet. If you click one of the buttons on Master, worksheets Sheet2, Sheet3, etc. will be made visible and then activated. If you click the button on Sheet2, Sheet3, etc., that worksheet will be hidden and Master will be activated.
Sub ToggleSheetVisibilityAndGo()
Dim shp As Shape
Dim sheetName As String
Dim v As Variant
Set shp = ActiveSheet.Shapes(Application.Caller)
sheetName = shp.TextFrame.Characters.Text
v = Split(sheetName, " ")
sheetName = v(UBound(v))
With Worksheets(sheetName)
    Select Case .Name
    Case "Master"
        ActiveSheet.Visible = xlSheetVeryHidden
    Case Else
        .Visible = xlSheetVisible
    End Select
    .Activate
End With
End Sub

Open in new window

ToggleSheetVisibilityAndGoQ28735396.xlsm

Author

Commented:
Hello byundt,

Your solution is just perfect for what i need.  

You make my day,

xxx

/mld

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial