Macro Excel - Activex Button that goes on a hidden sheet

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
mldaigle1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

byundtCommented:
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.
0
byundtCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mldaigle1Author Commented:
Hello byundt,

Your solution is just perfect for what i need.  

You make my day,

xxx

/mld
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.