1

我正在尝试一个很棒的功能,该功能显示一个列表框,该列表框充满了每个工作表上的所有形状。对于那件事我没有任何疑问。But I would like it when a shape is selected that the sheet, and shape is activate.

//Module(Custom)
Public Function getShape(Target As Variant) As Variant
    Dim ws As Worksheet   
    Dim sh As Shape
    Dim main As MainForm
    Set main = New MainForm
    For Each ws In ActiveWorkbook.Sheets
        For Each sh In ws.shapes
            main.AddShape sh, ws
        Next sh
    Next ws
    main.Show
End Function

//For MainForm
Dim shape_collection As Collection
Dim sheet_collection As Collection
Dim cnt As Integer

Private Sub ListBox1_Click()
    If ListBox1.ListIndex = -1 Then Exit Sub
    Dim ws As Worksheet
    Dim sh As Shape
    Set ws = sheet_collection.item(ListBox1.ListIndex + 1)
    Set sh = shape_collection.item(ListBox1.ListIndex + 1)
    Worksheets(ws.Name).Activate
    Worksheets(ws.Name).Select
    Worksheets(ws.Name).Visible = True
    sh.Select
End Sub

Private Sub UserForm_Initialize()
    Set shape_collection = New Collection
    Set sheet_collection = New Collection
End Sub

Public Sub AddShape(sh As Shape, ws As Worksheet)
    ListBox1.AddItem (sh.Name)
    shape_collection.Add sh
    sheet_collection.Add ws
End Sub
4

0 回答 0