Create macro that assigns value in a cell to Shape

bobshah2010

New Member
Joined
Nov 29, 2016
Messages
39
Hi Guys!

I'm having some trouble assigning a name to a shape via a macro.

Right now my macro is creating a list of visible sheets, and then creating an equal amount of shapes onto the worksheet.

I would like my macro to assign the shapes created with the value that is in the list created earlier (of all visible sheets). Ideally this shape should be linked i.e. "=$A$1" etc, not just named.

The next step that i have in mind is to assign these shapes with a macro - so that once you click on the shape it will re-direct you to the respective sheet name you clicked on.

This is the macro that i have used to assign shapes manually before:
Code:
Sub SheetLink()Application.GoToReference:= Worksheets (ActiveSheet.DrawingObjects(Application.Caller).Text).Range("A1")
End Sub

This is what i have so far:

Code:
Sub SheetNames()    Dim ws As Worksheet, ws1 As Worksheet
    Set ws1 = ActiveSheet
    Dim sq As Shape
    Dim rngRange As Range
    Dim Shp As Shape
    i = 1
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set rngRange = Sheets(1).Range("A1")
    ws1.Columns(1).Insert
    For Each ws In ThisWorkbook.Worksheets
        If ws.Visible = xlSheetVisible Then
            ws1.Cells(i, 1) = ws.Name
            Set sq = ws1.Shapes.AddShape(1, 50, 50, 100, 100)
            
            'Selection.Formula = ws1.Cells(i, 1)
            i = i + 1
        End If
    Next ws
'    For Each Shp In ActiveSheet.Shapes
'        Shp.Select
'        Selection.Formula = ws1.Columns(1)
'    Next
End Sub

Please ignore some of the commented areas. I've been trying different things, but none seem to be working.

To provide some context, i've previously been creating shapes and linking them to sheet names manually before. (i.e would copy and paste each sheet name into a column on a separate sheet. Then creating a few shapes and assigning the above macro to the shape.

I'm looking at automating this process, essentially creating a navigation page.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,215,558
Messages
6,125,504
Members
449,235
Latest member
Terra0013

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