我正在开发一个 Excel 电子表格,当选择下拉框值时,将弹出一个图像,如果选择另一个值,它将隐藏当前图像并弹出与所选内容相关的图像。我发现一些仅使用纸张并使用坐标定位图像的方法太耗时;这并不完全是我想要走的路线。在使用 StackOverflow 之前我已经做了相当多的研究,但到目前为止似乎没有任何效果。以下是我想要实现的目标。我试图将所有图像保留在电子表格中,这增加了另一个级别的挑战,但我相信有一种方法可以做到这一点,因为 Excel 在插入时会为图像分配一个数字前任。图9.
Sub Main()
If Range(G11).Value = "anything" Then
Picture1 show
Picture2 hide
End If
End Sub
任何帮助是极大的赞赏。谢谢
与其隐藏/移动/减小不需要的图片的大小,为什么不直接删除它呢?
Logic:
将所有图像保存在临时表中。当需要显示相关图片时,从临时表中获取它并删除前一个。
这是一个例子。
Sub Sample()
Select Case Range("G11").Value
Case "Picture 1": ShowPicture ("Picture 1")
Case "Picture 2": ShowPicture ("Picture 2")
Case "Picture 3": ShowPicture ("Picture 3")
Case "Picture 4": ShowPicture ("Picture 4")
End Select
End Sub
Sub ShowPicture(picname As String)
'~~> The reason why I am using OERN is because it is much simpler
'~~> than looping all shapes and then deleting them. There could be
'~~> charts, command buttons and other shapes. I will have to write
'~~> extra validation code so that those shapes are not deleted.
On Error Resume Next
Sheets("Sheet1").Shapes("Picture 1").Delete
Sheets("Sheet1").Shapes("Picture 2").Delete
Sheets("Sheet1").Shapes("Picture 3").Delete
Sheets("Sheet1").Shapes("Picture 4").Delete
On Error GoTo 0
Sheets("Temp").Shapes(picname).Copy
'<~~ Alternative to the below line. You may re-position the image
'<~~ after you paste as per your requirement
Sheets("Sheet1").Range("G15").Select
Sheets("Sheet1").Paste
End Sub
临时表快照
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)