• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

shift in image placement

Uri

New Member
impression.gif

favorite
I am using the Set Shp = ActiveSheet.Shapes.AddPicture command to insert a list of images in one column. All images have the same size. I first set the height and width of the cells and then start to place the images from top to bottom. The starting height is therefore (i-1)* (cell height) where i=1,2,3...n. I notice a gradual shift from the top of the cell. The first image is aligned with the top as expected, the second seems to be but later on a clear shift can be noticed. Is there an explanation for this shift? same happens when I have to place the images horizontally in one row.
 
Last edited by a moderator:
Welcome to the forum!

I am not sure what your goals are. I don't know what your math is about.

The usual one is to fit into a cell. Here is part of a macro:
e.g.
Code:
 'Resize cells and embed file:
  Columns("A").ColumnWidth = 16
  Set c = Cells(Rows.Count, "A").End(xlUp).Offset(1)
  For i = 0 To UBound(aPics)
    Rows(c.Row).RowHeight = 50
    Set s = ActiveSheet.Shapes.AddPicture _
      (aPics(i), msoFalse, msoTrue, _
        c.Left, c.Top, c.Width, c.RowHeight) 'embed files
    s.LockAspectRatio = False
    'With ActiveSheet.Pictures.Insert(aPics(i)) 'link files
    '  .ShapeRange.LockAspectRatio = False
    '  .Width = c.Width
    '  .Height = c.RowHeight
    '  .Top = c.Top
    '  .Left = c.Left
    'End With
    Set c = c.Offset(1)
  Next i
 
Uri

Firstly, Welcome to the Chandoo.org Forums

This error is due to small rounding errors

To do what you want simply reference the cells .Top and .Left properties as the anchor locations for the images, rather than trying to calculate what they should be
 
Thank you Kenneth! it did help!
Welcome to the forum!

I am not sure what your goals are. I don't know what your math is about.

The usual one is to fit into a cell. Here is part of a macro:
e.g.
Code:
 'Resize cells and embed file:
  Columns("A").ColumnWidth = 16
  Set c = Cells(Rows.Count, "A").End(xlUp).Offset(1)
  For i = 0 To UBound(aPics)
    Rows(c.Row).RowHeight = 50
    Set s = ActiveSheet.Shapes.AddPicture _
      (aPics(i), msoFalse, msoTrue, _
        c.Left, c.Top, c.Width, c.RowHeight) 'embed files
    s.LockAspectRatio = False
    'With ActiveSheet.Pictures.Insert(aPics(i)) 'link files
    '  .ShapeRange.LockAspectRatio = False
    '  .Width = c.Width
    '  .Height = c.RowHeight
    '  .Top = c.Top
    '  .Left = c.Left
    'End With
    Set c = c.Offset(1)
  Next i
 
Thank you Hui! It did help!
Uri

Firstly, Welcome to the Chandoo.org Forums

This error is due to small rounding errors

To do what you want simply reference the cells .Top and .Left properties as the anchor locations for the images, rather than trying to calculate what they should be
 
Back
Top