Excel VBA - Convert existing image in cell to comment picture

杀马特。学长 韩版系。学妹 提交于 2021-01-29 10:14:53

问题


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

any thoughts?

CJ


回答1:


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

See

Making shapes invisible/visible in excel through VBA

with

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

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

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


来源:https://stackoverflow.com/questions/60284915/excel-vba-convert-existing-image-in-cell-to-comment-picture

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!