Hi
Am trying to insert images into a sheet. And tie the picture to the top left of a cell.
It does this without a problem, however when I insert the next image in rows further down, the first image is shifted to the right. It's kept it's top position with the original cell, but lost the left information.
Each time I add a new image all the images above will shift to the right so they are all staggered.
Attached is the code I am using. I tried the various .placement options with no difference. .XlMove but XlMove ANd Size is not appropriate as I am sizing the images to the column width
variables defined elsewhere in the code are: image = image name from other file and f is the row number I am currently inserting the image on.
So my code is as follows:
'image insertion
If image <> "" Then
Dim myPic As Object
Set myPic = ActiveSheet.Pictures.Insert("D:\images\" + image)
With myPic
ActiveSheet.Pictures.Top = ActiveSheet.Cells(f, 2).Top
ActiveSheet.Pictures.Left = ActiveSheet.Cells(f, 2).Left
ActiveSheet.Pictures.ShapeRange.LockAspectRatio = msoTrue
'****.ShapeRange.Height = ws.[a1].RowHeight
ActiveSheet.Pictures.ShapeRange.Width = ActiveSheet.Cells(f, 2).Width
'ActiveSheet.Pictures.Placement = xlFreeFloating
End With
Set myPic = Nothing
End If
Suggestions greatly appreciated. I'm going insane
ps. Please be gentle as I am a novice at VBA. Thanks
Am trying to insert images into a sheet. And tie the picture to the top left of a cell.
It does this without a problem, however when I insert the next image in rows further down, the first image is shifted to the right. It's kept it's top position with the original cell, but lost the left information.
Each time I add a new image all the images above will shift to the right so they are all staggered.
Attached is the code I am using. I tried the various .placement options with no difference. .XlMove but XlMove ANd Size is not appropriate as I am sizing the images to the column width
variables defined elsewhere in the code are: image = image name from other file and f is the row number I am currently inserting the image on.
So my code is as follows:
'image insertion
If image <> "" Then
Dim myPic As Object
Set myPic = ActiveSheet.Pictures.Insert("D:\images\" + image)
With myPic
ActiveSheet.Pictures.Top = ActiveSheet.Cells(f, 2).Top
ActiveSheet.Pictures.Left = ActiveSheet.Cells(f, 2).Left
ActiveSheet.Pictures.ShapeRange.LockAspectRatio = msoTrue
'****.ShapeRange.Height = ws.[a1].RowHeight
ActiveSheet.Pictures.ShapeRange.Width = ActiveSheet.Cells(f, 2).Width
'ActiveSheet.Pictures.Placement = xlFreeFloating
End With
Set myPic = Nothing
End If
Suggestions greatly appreciated. I'm going insane
ps. Please be gentle as I am a novice at VBA. Thanks