VBA - Paste image from my clipboard below the last image

christiancdv

New Member
Joined
Aug 15, 2022
Messages
4
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Hello, 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.

Best regards,
Christian.

2c571f96e06695263f95c34a1f055db5.png
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Something similar to what I want to get..

VBA Code:
Option Explicit

Sub Sample()
    Dim myShape As Shape, shp As Shape
    Dim sHeight As Double, sTopp As Double

    For Each shp In ActiveSheet.Shapes
        If shp.Top > sTopp Then
            sTopp = shp.Top
            sHeight = shp.Height
        End If
    Next

    Set myShape = ActiveSheet.Shapes("Label")

    myShape.Copy

    ActiveSheet.Paste

    With Selection
        .Top = sTopp + sHeight + 10
        .Left = myShape.Left
    End With
End Sub
 

Attachments

  • 1661954149847.png
    1661954149847.png
    312 bytes · Views: 4
Upvote 0
VBA Code:
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 = 2 And shp.TopLeftCell.Row = 2 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
            
            'add border to image
            shp.DrawingObject.Border.LineStyle = 1
            shp.DrawingObject.Border.Color = vbBlack
            shp.DrawingObject.Border.Weight = 2
            
            Set prvShape = shp
        Next shp
    End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,861
Messages
6,181,448
Members
453,042
Latest member
AbdelrahmanExcel

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