I am having an issue with a sub I created to add an image into the comment of an Excel spread sheet. The code below attaches the image, but the width and height are not correct. For images that are narrower than they are tall, it tends to make the width almost 0 while applying a height value. For images that are wider than they are tall, the comment(image) is mostly correct but with an incorrect aspect ratio.
Any thoughts on what I have missed?
Sub AddPictureComment(ByVal strPartName As String, ByVal intExcelRow As Integer, ByRef xlsWorkSheet As Object)
'~~> Set what needs to go into comments
Dim strPartImageName As String = strFilePath & strPartName & ".jpg"
Dim bmpImageForSize As New Bitmap(strPartImageName)
'~~> Verify/Record the information
lw.Writeline("Cell: A" & intExcelRow)
lw.Writeline(" -Image : " & strPartImageName)
lw.WriteLine(" -Height : " & bmpImageForSize.height)
lw.WriteLine(" -Width : " & bmpImageForSize.width)
lw.WriteLine("")
'~~> Add the comment
With xlsWorkSheet.Range("A" & intExcelRow).AddComment(strPartName)
.Shape.Height = bmpImageForSize.Height
.Shape.Width = bmpImageForSize.Width
.Shape.Fill.UserPicture(strPartImageName)
End With
End Sub
re: excel images in comments
When adding an image to a comment in interactive Excel, there is an option to "lock aspect ratio". You might try recording an Excel macro using this option and examining the resulting code to see what you need to add to the journal code to do the same.