1

すべてのワークシートのすべての図形で満たされた ListBox を表示する関数を改善しようとしています。私はそれで問題ありません。ただし、形状が選択されている場合は、シートと形状がアクティブになるようにしたいと思います。

//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