Excel VBA-将单元格中的现有图像转换为注释图片 [英] Excel VBA - Convert existing image in cell to comment picture

查看:59
本文介绍了Excel VBA-将单元格中的现有图像转换为注释图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Excel中使用VBA将一列中的一堆图片(每个单元格一个)转换为弹出的注释图像,以使工作表更易于阅读.我可以通过遍历形状找到所需的图像,并将其设置为对象.但我似乎无法使用该onject来填充评论字段.它似乎正在寻找真实的文件路径.
我并不是特别想保存每个图像然后重新加载它,这似乎毫无意义.

I'm trying to use VBA in Excel to convert a bunch of pictures in a column (one per cell) to a pop up comment image instead so that the sheet is more easily readable. I can find the image I need by iterating through the shapes, and I can set this as an object; but I can't seem to use that onject to populate the comment field. It seems to be looking for a true file path instead.
I don't particularly want to have to save each image and then reload it, seems kind of pointless.

 For Each Pic In ActiveSheet.Shapes
    If Pic.TopLeftCell.Address = ActiveCell.Address Then
      If Pic.Type = msoPicture Then
        Pic.Select
        Application.ActiveCell.AddComment.Shape.Fill.UserPicture **(ActiveSheet.Shapes(Pic.name))** 'if I use a path here its okay
        'SelectPictureAtActiveCell = name
        Exit For
      End If
    End If
   Next

有什么想法吗?

CJ

推荐答案

如果您选择一个特定的单元格,那么我想显示一张图像

I think you want to show one image if you select a specific cell then

请参见

通过VBA在excel中使形状不可见/可见

使用

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Macro1
End Sub

您可以使用以下方法隐藏和显示图像ActiveSheet.Shapes("ImageName").Visible = False或True

You can make images hide and show using ActiveSheet.Shapes("ImageName").Visible = False or True

例如,当您单击单元格A1时,第一个图像是隐藏的,否则所有图像都是可见的

for example when you click on cell A1 first image is hidden else all images are visible

Sub Macro1()

Dim shp As Shape

If ActiveCell.Address = "$A$1" Then
For Each shp In ActiveSheet.Shapes
ActiveSheet.Shapes(1).Visible = False
' or you can use image name as
'ActiveSheet.Shapes("ImageName").Visible = False
'shp.Visible = False
Next
Else
For Each shp In ActiveSheet.Shapes
shp.Visible = True
Next
End If
End Sub

这篇关于Excel VBA-将单元格中的现有图像转换为注释图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆