Consulting

Results 1 to 2 of 2

Thread: Move over Picture

  1. #1

    Move over Picture

    Hi ,

    I have inserted a picture object in my excell sheet cell , displayed as an icon. I want to open this picture if i move the mouse over the picture and once the mouse is away from that picture it should be close.

    I have tried using CommandButton_moveover ..but could not get exactly what i wanted.

    i know it is not fair to ask full length code here.......but i am total new bie to excel VBA......please help
    Last edited by peas_for_xls; 06-30-2008 at 06:04 AM.

  2. #2
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    228
    Location
    Quote Originally Posted by peas_for_xls
    Hi ,

    I have inserted a picture object in my excell sheet cell , displayed as an icon. I want to open this picture if i move the mouse over the picture and once the mouse is away from that picture it should be close.

    I have tried using CommandButton_moveover ..but could not get exactly what i wanted.

    i know it is not fare to ask full length code here.......but i am total new bie to excel VBA......please help
    Hi there,

    I was trying to do something similar to this a while ago, mouse over to make a graph visible, then remove when mouse moves away.

    I found the code below when I was looking into it. Never really took it any further as I opted to make the cell a hyperlink to the graphs, easier at the time.

    Code provided by AndrewJ (from another site)
    [vba]
    Option Explicit
    Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' do macro commands here:

    CommandButton1.BackColor = RGB(200, 200, 200) ' grey
    ActiveSheet.Shapes("Label2").Visible = True ' display label2

    If ActiveSheet.Pictures("Picture1").Visible = False Then ' test if picture is showing

    ActiveSheet.Pictures("Picture1").Visible = True ' if picture was not visible, make it visible
    End If

    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = True ' make background label visible (to detect mouseoff)
    End Sub
    Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

    ' do macro commands here:

    CommandButton2.BackColor = RGB(200, 200, 200) ' grey
    ActiveSheet.Shapes("Label3").Visible = True ' display label3

    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = True ' make background label visible (to detect mouseoff)
    End Sub
    Private Sub CommandButton3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ' do macro commands here:

    CommandButton3.BackColor = RGB(200, 200, 200) ' grey
    ActiveSheet.Shapes("Label4").Visible = True ' display label4

    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = True ' make background label visible (to detect mouseoff)
    End Sub
    Private Sub CommandButton4_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

    ' do macro commands here:

    CommandButton4.BackColor = RGB(200, 200, 200) ' grey
    ActiveSheet.Shapes("Label5").Visible = True ' display label5

    Cells(14, 8).FormulaR1C1 = "=TODAY()" ' modify cells
    Cells(13, 8).Value = "Today's Date:"

    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = True ' make background label visible (to detect mouseoff)

    End Sub
    Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If CommandButton1.BackColor <> RGB(50, 50, 255) Then ' test if cb1 is blue or grey

    CommandButton1.BackColor = RGB(50, 50, 255) ' if grey, change to blue

    End If

    If CommandButton2.BackColor <> RGB(50, 50, 255) Then

    CommandButton2.BackColor = RGB(50, 50, 255) ' blue

    End If

    If CommandButton3.BackColor <> RGB(50, 50, 255) Then

    CommandButton3.BackColor = RGB(50, 50, 255) ' blue

    End If

    If CommandButton4.BackColor <> RGB(50, 50, 255) Then

    CommandButton4.BackColor = RGB(50, 50, 255) ' blue

    End If

    If ActiveSheet.Shapes("Label2").Visible = True Then

    ActiveSheet.Shapes("Label2").Visible = False ' turn off label

    End If

    If ActiveSheet.Shapes("Label3").Visible = True Then

    ActiveSheet.Shapes("Label3").Visible = False ' turn off label

    End If

    If ActiveSheet.Shapes("Label4").Visible = True Then

    ActiveSheet.Shapes("Label4").Visible = False ' turn off label

    End If

    If ActiveSheet.Shapes("Label5").Visible = True Then

    ActiveSheet.Shapes("Label5").Visible = False ' turn off label

    End If

    If Cells(13, 8).Value > 1 Then ' test if cells are occupied

    Cells(14, 8).ClearContents ' if they are, clear them
    Cells(13, 8).ClearContents

    End If

    If ActiveSheet.Pictures("Picture1").Visible = True Then ' test if picture is visible

    ActiveSheet.Pictures("Picture1").Visible = False ' if it is, make it invisible
    End If


    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = False
    ' once mouseover has registered (meaning that the mouse left a commandbutton, perform all the code above
    ' and finish with this line so label1 is not clickable. Label1 should be reactivated on any mouseover
    ' of any button (see CommandButtonX_MouseMove subs and OptionButton1_MouseMove sub)
    End Sub
    Private Sub OptionButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    If ActiveSheet.Pictures("Picture1").Visible = False Then ' test if picture is showing

    ActiveSheet.Pictures("Picture1").Visible = True ' if it isnt, make it visible
    End If


    ' keep this last line no matter what you change above
    ActiveSheet.Shapes("Label1").Visible = True ' make background label visible (to detect mouseoff)
    End Sub
    [/vba]

    I had some success in getting this to work, but couldn't work out how to adapt it enough for my needs.

    Hope it helps

    Marshybid

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •