在Excel 2007或VBA脚本上完成noob ...
我需要以编程方式选择一些图像(实际上它们都是相同的图像)并隐藏它们,或者如果不可能的话,在工作表的某些位置再现固定图像......
要显示的图像数量由某些行范围的计数控制,如果范围中的某些行填充了数据,则必须显示一个图像,否则,将不显示该图像......这是在文件的另一张纸上完成的......
有没有办法实现这个目标?
答案 0 :(得分:1)
以下是我使用的内容:
' Manages Images in Img worksheet, according to values captured at Ref worksheet
' Ref = worksheet to know if image is to be displayed,
' Cells Ax are empty when we're not displaying image or else it'll be displayed
' Img = worksheet for the images, each image is named 'Picture x'
' N = Max amount of images to show/hide
Public Function ManImages(ByVal N As Integer, _
ByVal Ref As Integer, ByVal Img As Integer)
Set ref = Worksheets(Ref)
For x = 1 To N
If ref.Range("A" & x) <> "" Then
a = HideImage(x, False, Img)
Else
a = HideImage(x, True. Img)
End If
Next x
End Sub
' Hides or Shows images by index according to fixed name of the shapes
' ind is the image to manage
' st is True to show, False to hide
' Img is the worksheet where the images live
Public Function HideImage(ByVal ind As Integer, ByVal st As Boolean,
ByVal Img As Integer) As String
Set doc = Worksheets(Img)
doc.Shapes("Picture " & ind).Visible = st
HideImages = st
End Function