获取单元格的注释背景图像(.Shape.Fill.UserPicture)

如何获得单元格注释背景图像的尺寸?

我创build了一个完全由背景图片组成的评论,

ActiveCell.Comment.Shape.Fill.UserPicture l_strFullPathOfImagePNG

我希望能够,

  1. select单元格。
  2. 运行一个调整注释大小的macros,使背景图像不是模糊的,而是按照像素的大小确定像素大小。

为此,我需要知道背景图片的尺寸。

如果我知道创build背景图像的图像文件的完整path,则可以调整单元格注释的大小以实现我想要的效果:

 Sub CommentResizeToFitBackgroundImage() Dim l_strFullPathOfImagePNG As String Dim l_lImageWidth_pixels As Long, _ l_lImageHeight_pixels As Long l_strFullPathOfImagePNG = "C:\……\BackgroundImage.png" 'Get the width and height in pixels of the image to be inserted GetPNGDimensions _ l_strFullPathOfImagePNG, _ l_lImageWidth_pixels, _ l_lImageHeight_pixels With ActiveCell.Comment.Shape '0.75 scale factor was arrived at empirically 'and probably true only for my machine .Width = l_lImageWidth_pixels * 0.75 .Height = l_lImageHeight_pixels * 0.75 End With End Sub 

但是,我想这样做到现有的评论,不再有一个有效的图像文件阅读,所以我需要得到的背景图像的尺寸。

.Comment.Shape.ScaleHeight 1, msoTrue看起来很有希望,但失败,错误“RelativeToOriginalSize参数仅适用于图片或OLE对象”。

MsoFillType.msoFillPicture = MsoFillType.msoFillPicture ; 所以我确实有一张照片,而不是一个坚实的背景,渐变,图案或纹理; 所以我不知道编译器在抱怨什么。

最后,显然, .Comment.Shape.Fill.PictureEffects不适用于评论。