i need help in the creation of the macro. Ill try to explain the function i want it to have:
- With the screenshot already on my clipboard, I need all the different screenshot, that are going below the blue rectangle, to mantain the same width (30,4cm) and column (B:B) of this rectangle). Below I show an example of what I need. Therefore, every time I paste a new screenshot the macro should search the last image and put the new one beneath the last one.
- Also, it would be perfect if between each screenshot it would mantain a gap.
CodePudding user response:
This might help get you started. This macro/function will line up all images under that blue shape that starts in A1 in the order that they have been pasted into the worksheet. A small gap will be between them and they will be resized to match the width of the header shape.
Sub LineUpAllShapes()
Dim ws As Worksheet
Dim shp As Shape, shpHeader As Shape
Dim colOtherShapes As New Collection
Dim prvShape As Shape
Set ws = ActiveSheet
For Each shp In ws.Shapes
If shp.TopLeftCell.Column = 1 And shp.TopLeftCell.Row = 1 Then
Set shpHeader = shp
Else
colOtherShapes.Add shp
End If
Next shp
If Not shpHeader Is Nothing Then
Set prvShape = shpHeader
For Each shp In colOtherShapes
shp.Width = prvShape.Width
shp.Top = prvShape.Top prvShape.Height 5
shp.Left = prvShape.Left
Set prvShape = shp
Next shp
End If
End Sub
And this one will only line up the last added image under the previously added image just before it
Sub LineUpLastAddedImage()
Dim ws As Worksheet
Dim shp As Shape
Dim prvShape As Shape
Set ws = ActiveSheet
Dim shpLastAdded As Shape
Set shpLastAdded = ws.Shapes.Item(ws.Shapes.Count)
Set prvShape = ws.Shapes.Item(ws.Shapes.Count - 1)
shpLastAdded.Left = prvShape.Left
shpLastAdded.Top = prvShape.Top prvShape.Height 5
shpLastAdded.Width = prvShape.Width
End Sub