Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

VBA: auto group multile pictures kept in each excel cell

I have multiple images in each cell in column B. There are 1000 rows.

I need a VBA to "auto group" pictures available in each row. But with the below code I can't perform the action in a single cell at a time.

Sub groupimagesandshape()
' group images and shapes in each cell of column B

Sheet1.Shapes.SelectAll
Selection.Group

ActiveWorkbook.Save

End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

the shapes are in cells in column B then this code will work.

Sub test()
    Dim shp As Shape, shpU As Shape
    Dim vArray(), vR()
    Dim Ws As Worksheet, rng As Range
    Dim n  As Long, k As Integer
    Dim v As Variant

    Set Ws = ActiveSheet

    Ws.Shapes.SelectAll
    Selection.Ungroup

    For Each shp In Ws.Shapes
        n = n + 1
        ReDim Preserve vArray(1 To n)
        vArray(n) = shp.Name
    Next shp
    For Each rng In Ws.Range("b1:b1000")
        k = 0
        For Each v In vArray
            If Not Intersect(Ws.Shapes(v).TopLeftCell, rng) Is Nothing Then
                k = k + 1
                ReDim Preserve vR(1 To k)
                vR(k) = v
            End If
        Next v
        If k > 1 Then
            Ws.Shapes.Range(vR).Group
        End If
    Next rng
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...