Stacking Pictures Vertically VBA

jlhoover3

Board Regular
Joined
Nov 9, 2015
Messages
58
Office Version
  1. 365
Platform
  1. Windows
Hello everyone!

I am having problems figuring out a way to stack images or place images vertically on excel. When saying that, I want to insert a picture and have it move directly below the previous image that was inserted. Usually this wouldn't be a problem, however the images have a different height and so I'm not sure how to do this. Any help would be great and hoping this is making sense. Thanks for you time!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
After inserting a picture, you can use its Top and Height properties to calculate the Top property for the next picture.
 
Upvote 0
After inserting a picture, you can use its Top and Height properties to calculate the Top property for the next picture.

Thanks for the reply. Still a little bit confused on how i can place the image right below the previous image. This is what I have below, thanks!

Code:
Sub BrandImage()Dim r As Range
Dim WS As Worksheet
Dim imagePath As String
Dim img As Picture


Set WS = Worksheets("PictureTest")
Set r = WS.Range("E4:H16")
imagePath = Range("A1").Value
Set img = WS.Pictures.Insert(imagePath)
img.Name = "Brand"
With img
    .ShapeRange.LockAspectRatio = msoTrue
    .Height = r.Height
    .Top = r.Top
    .Left = r.Left
End With


Set s = r
imagePath = Range("A2").Value
Set img = WS.Pictures.Insert(imagePath)
img.Name = "Type1"
With img
    .ShapeRange.LockAspectRatio = msoTrue
    .Left = s.Left
    .Height = s.Height
    .Top = s.Top
    
End With


End Sub
 
Upvote 0
For example,

Code:
Sub BrandImage()
  Dim wks           As Worksheet
  Dim cell          As Range
  Dim pic           As Picture
  Dim dTop          As Double
  Dim dLft          As Double

  Set wks = Worksheets("PictureTest")
  wks.Select  ' not necessary, but allows you to watch
  With wks.Range("E4")
    dTop = .Top
    dLft = .Left
  End With

  For Each cell In Range("A1:A10")  ' paths & filenames
    With cell
      If Len(.Text) > 0 And Len(Dir(.Text)) > 0 Then
        Set pic = wks.Pictures.Insert(.Text)
        With pic
          .ShapeRange.LockAspectRatio = msoTrue
          .Width = 100
          .Left = dLft
          .Top = dTop
          .Name = cell.Offset(, 1).Text ' names in col B
          dTop = dTop + .Height
        End With
      End If
    End With
  Next cell
End Sub
 
Upvote 0
For example,

Code:
Sub BrandImage()
  Dim wks           As Worksheet
  Dim cell          As Range
  Dim pic           As Picture
  Dim dTop          As Double
  Dim dLft          As Double

  Set wks = Worksheets("PictureTest")
  wks.Select  ' not necessary, but allows you to watch
  With wks.Range("E4")
    dTop = .Top
    dLft = .Left
  End With

  For Each cell In Range("A1:A10")  ' paths & filenames
    With cell
      If Len(.Text) > 0 And Len(Dir(.Text)) > 0 Then
        Set pic = wks.Pictures.Insert(.Text)
        With pic
          .ShapeRange.LockAspectRatio = msoTrue
          .Width = 100
          .Left = dLft
          .Top = dTop
          .Name = cell.Offset(, 1).Text ' names in col B
          dTop = dTop + .Height
        End With
      End If
    End With
  Next cell
End Sub

I never thought of using a For Statement for this situation. I appreciate everything!!!! Works perfectly :)
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,317
Members
449,218
Latest member
Excel Master

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