Macro to open hidden tab - using shape as button

ThatMasonGUy

New Member
Joined
Mar 29, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I'm looking to make a super simple macro that just pulls the text out of a shape and uses that to unhide and open a tab on click.

Sub ButtonToHiddenSheet()

Dim ShtName As String
ShtName = SHAPE TEXT
Sheets(ShtName).Visible = xlSheetVisible
Sheets(ShtName).Select

End Sub

I just don't know how to & cannot for the life of me find how to copy the text from within a shape, help please!

Pic of the buttons, just incase.
1663135287357.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I've managed to get it to work with the below code.

Sub ButtonToHiddenSheet()

Dim ShtName As String

ActiveSheet.Shapes(Application.Caller).Select

ShtName = Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text

Sheets(ShtName).Visible = xlSheetVisible
Sheets(ShtName).Select

End Sub
 
Upvote 0
Solution
Think that can be just:
VBA Code:
ShtName = Selection.ShapeRange(1).TextFrame2.TextRange
 
Upvote 0
Hi,
should not need to select the object

VBA Code:
Sub SHAPE_CLICK()
    Dim SheetName   As String
    Dim shp         As Shape
   
    Set shp = ActiveSheet.Shapes(Application.Caller)
   
    SheetName = shp.TextFrame.Characters.Text
   
    If Evaluate("ISREF('" & SheetName & "'!A1)") Then
        With Worksheets(SheetName)
            .Activate
            .Visible = Not .Visible
        End With
    End If

End Sub

Code should toggle the visibility of the sheet

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,670
Messages
6,120,831
Members
448,990
Latest member
rohitsomani

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