首页 > 解决方案 > Excel VBA 自动功能重置/图像加载

问题描述

我正在使用函数 OnMouseOver 根据单元格中的文本加载特定图片。

Dim DoOnce As Boolean
Public Function OnMouseOver(URL As String, TheCell As Range)
Reset
If Not DoOnce Then
    DoOnce = True
    With ActiveSheet.Pictures.Insert(URL)
        With .ShapeRange
            .LockAspectRatio = msoTrue
            .Width = 300
            .Height = 300
        End With
        .Left = Cells(TheCell.Row, TheCell.Column + 1).Left
        .Top = Cells(TheCell.Row, TheCell.Column + 1).Top
        .Placement = 1
        .PrintObject = True
    End With
End If
End Function

Public Function Reset()
If DoOnce Then
    DoOnce = False
    ActiveSheet.Pictures.Delete
End If
End Function

我的问题是我必须使用“重置”功能来删除加载的图片。所以我必须将鼠标移动到下一个单元格,并具有删除图片的功能。是否可以修改仅当鼠标悬停在单元格上时才显示图片的功能?

标签: excelvba

解决方案


推荐阅读