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

时间:2015-09-30 15:12:40

标签: excel image vba

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

我使用

创建了一个仅由背景图片组成的评论

ActiveCell.Comment.Shape.Fill.UserPicture l_strFullPathOfImagePNG

我希望能够,

  1. 选择单元格。
  2. 运行一个调整注释大小的宏,这样背景图像就不会模糊,而是确定像素的像素。
  3. 要做到这一点,我需要知道背景图像的尺寸。

    如果我知道创建背景图像的图像文件的完整路径,我可以调整单元格注释的大小以达到我想要的效果:

    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对象”。

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

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

0 个答案:

没有答案
相关问题