开发者

Excel VBA.Program Event:=ActiveCell, Image:=Visible

I am using Excel 2000 and need assistance in programming an image to toggle between visible and hidden when a cell is active or a simulation of that event.

Given a list of five items in column A, a separate image is associated with each item. On opening the file all images should be hidden except in the event the file is open with one of the items actively selected. As the user clicks or cursors up/down column A the image shown changes to the associated image.

I can easily do this in other programs/languages开发者_运维百科 but I am restricted to Excel.


You can trap worksheet level events in the code module behind the worsheet. Right click the sheet tab, View code, and paste the following

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim sPic As String

    On Error GoTo errExit
    Me.Pictures.Visible = False ' hides ALL pictures
    If Not Intersect(Range("A1:A5"), Target(1)) Is Nothing Then
        Select Case Target.Address(0, 0)
        Case "A1": sPic = "Picture 1"
        Case "A2": sPic = "Picture 2"
        Case "A3": sPic = "Picture 3"
        Case "A4": sPic = "Picture 4"
        Case "A5": sPic = "Picture 5"
        End Select
    Me.Pictures(sPic).Visible = True
End If

errExit:

End Sub

Adjust the names of your images to suit. To see the image name select it and look at the "Names" box left of the input bar.

Clsoe the VBE (visual basic editor) when done. You many need to adjust your macro security settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜