Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel 2007 reference image to programatically hide it / reproduce it

complete noob on Excel 2007 or VBA scripts here...

I need to programatically select some images (they're all the same image in fact) and hide them, or if not possible, to reproduce a fixed image in certain places of a worksheet...

The amount of images to be displayed is controlled by the count of some range of rows, if some row in the range is filled with data, then one image must be displayed, if not, then that image won't be displayed... this is done on another sheet on the document...

Is there any way to achieve this?

like image 351
Javier Novoa C. Avatar asked Nov 18 '25 01:11

Javier Novoa C.


1 Answers

Here's what I used:

' 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
like image 195
Javier Novoa C. Avatar answered Nov 20 '25 12:11

Javier Novoa C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!