excel里面能控制图片隐藏和显示的代码
发布网友
发布时间:2022-03-09 00:40
我来回答
共2个回答
热心网友
时间:2022-03-09 02:10
ActiveWorkbook.DisplayDrawingObjects = xlHide
本句是不显示图片
ActiveWorkbook.DisplayDrawingObjects = xlDisplayShapes
本句是显示
你可以在你文件的有图片的(比如sheet1)的change事件中加入以下代码(假设你要输入显示或者隐藏内容的格为B1)
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" And Target = "隐藏" Then ActiveWorkbook.DisplayDrawingObjects = xlHide
If Target.Address = "$B$1" And Target = "显示" Then ActiveWorkbook.DisplayDrawingObjects = xlDisplayShapes
End Sub
加入代码的方法,是打开VB编辑器,双击左边的sheet1,在右边的空白处粘贴以上代码就可以了
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$1" And Target = "隐藏" Then ActiveSheet.Shapes("Picture 1").Visible = False
If Target.Address = "$B$1" And Target = "显示" Then ActiveSheet.Shapes("Picture 1").Visible = True
End Sub
这是对单张图片的操作方法。至于你的图片如果较多,那么哪张是Picture 1,就要自己试验出来了。如果对其中几张操作,那么就把then 后面的句子重写几遍,Picture 1改成2,3....也就行了
再补充一句,你把= "显示"改成<>"隐藏"就可以了
热心网友
时间:2022-03-09 03:28
ActiveWorkbook.DisplayDrawingObjects = xlHide