In my workbook, I give the user the ability to insert a picture file into one of the worksheets. I have code that does this for them, so the sheet can remain protected the rest of the time. I also allow them to change the height of one of the rows in that sheet, in case they need a bit more room for their picture.
I set the aspect ratio of the picture to be locked in my code, but if the picture fully extends over the row that they change the height on, the picture gets longer or shorter as the row height is changed. I do not want this to happen. I do want them to be able to adjust the size of the picture, however, so I have to leave the sheet unprotected during this process.
Any idea how I can stop the aspect ratio from changing when the row height changes?
Here's the code I use to insert a picture into the worksheet:
Note: The variable PicPathAndName is determined by some other code, depending on if the user is on Windows or Mac. I didn't include it here because the picture file is inserted into the sheet with no problem.
I set the aspect ratio of the picture to be locked in my code, but if the picture fully extends over the row that they change the height on, the picture gets longer or shorter as the row height is changed. I do not want this to happen. I do want them to be able to adjust the size of the picture, however, so I have to leave the sheet unprotected during this process.
Any idea how I can stop the aspect ratio from changing when the row height changes?
Here's the code I use to insert a picture into the worksheet:
Code:
Dim Pic As Shape
Set Pic = ThisWorkbook.ActiveSheet.Shapes.AddPicture(PicPathAndName, _
linktofile:=msoFalse, savewithdocument:=msoTrue, Left:=0, Top:=0, Width:=-1, Height:=-1)
With Pic
.LockAspectRatio = msoTrue
.Top = ThisWorkbook.ActiveSheet.Cells(5, 9).Top
.Left = ThisWorkbook.ActiveSheet.Cells(5, 9).Left
.Placement = 1
End With
Note: The variable PicPathAndName is determined by some other code, depending on if the user is on Windows or Mac. I didn't include it here because the picture file is inserted into the sheet with no problem.