Closed Thread
Results 1 to 19 of 19

Custom message with mouseover

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Hi Bryan,

    Haven't looked at the attachment yet. I am sure it is better than what I came up with.

    Meanwhile, Michael, here is what I came up with ... replace the code above with the code below (on the Pareto chart's code window). To use this, you need to have first created a shape (I chose a rectangle, but you can make it any auto shape you like) and Name it "CommentBox" (easiest way to do this is to use the Name box that is to the left of the Excel formula bar ... always remember to press Enter after typing in a name or the name will not "stick").

    Dim keepA As Long, keepB As Long
    
    Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim searchModel As Range, searchColor As Range
    Dim searchComment As Range, lastRow As Long
    Dim ID As Long, a As Long, b As Long
    Dim s As Series, p As Point
    Dim sh As Shape, strComment As String
        
        On Error GoTo leave
        Me.GetChartElement x, y, ID, a, b
        Set sh = Me.Shapes("CommentBox")
        Select Case True
            Case a = keepA And b = keepB
                'sh.Visible = False
            Case ID = 3
                Set ws1 = Sheet2
                myColor = ws1.Cells(4, a + 1)
                myModel = ws1.Cells(b + 4, 1)
                
                'do not need these, but this is what a & b represent:
                Set s = Me.SeriesCollection(a)
                Set p = s.Points(b)
    '            MsgBox WorksheetFunction.Index _
    '                    (Me.SeriesCollection(a).XValues, b)
    '            MsgBox WorksheetFunction.Index _
    '                    (Me.SeriesCollection(a).Values, b)
                    
                Set ws2 = Sheet3
                lastRow = ws2.Cells.SpecialCells(xlLastCell).Row
                
                Set searchModel = Range(ws2.Cells(1, 1), ws2.Cells(lastRow, 1))
                Set searchColor = Range(ws2.Cells(1, 2), ws2.Cells(lastRow, 2))
                Set searchComment = Range(ws2.Cells(1, 5), ws2.Cells(lastRow, 5))
    
                'MsgBox myColor, vbOKOnly, myModel
                For i = 1 To lastRow
                    If searchModel.Cells(i) = myModel Then
                        If searchColor.Cells(i) = myColor Then
                            strComment = vbLf & s.Name & vbLf
                            strComment = strComment & searchComment.Cells(i) & vbLf
                            With sh
                                .TextFrame.Characters.Text = strComment
                                .TextFrame.AutoSize = True
                                .Visible = True
                                'need to convert pixels to twips
                                'to get the Left & Top exactly right
                                .Left = x * 2 / 3
                                .Top = y * 2 / 3
                            End With
                            Exit For
                        End If
                    End If
                Next i
                'remember these so we do not keep doing the same thing
                'over and over again
                keepA = a
                keepB = b
            Case Else
                sh.Visible = False
                keepA = 0
                keepB = 0
        End Select
    
    leave:
    End Sub

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Bryan, that is a great form you created! I am sure I will find it useful. I will be sure to credit you in any code I use it with.

    Michael, take at look at Bryan's workbook. It might appear too "formal" for the impact you are trying to achieve. (Although, for MY purposes, it looks much more professional than an autoshape!)

    If you prefer the professional look and want me to put it into your workbook, let me know. Shouldn't be a problem.

  3. #3
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by MSP77079
    Bryan, that is a great form you created! I am sure I will find it useful. I will be sure to credit you in any code I use it with.

    Michael, take at look at Bryan's workbook. It might appear too "formal" for the impact you are trying to achieve. (Although, for MY purposes, it looks much more professional than an autoshape!)

    If you prefer the professional look and want me to put it into your workbook, let me know. Shouldn't be a problem.
    Would that I could claim such code, it was found at Stephen's site as mentioned, I simply thought it might help as 'floating message boxes' are not (to my knowledge) commonplace items.

    ---
    Si fractum non sit, noli id reficere.

  4. #4
    Registered User
    Join Date
    06-05-2006
    Posts
    13

    thank you!

    Thank you both MSP and Bryan!

    I'll try to make Bryan's solution work if I have time to make my material look more professional but right now the MSP solution is exactly what I originally had in mind.

    Thank you again very much!
    michael

  5. #5
    Registered User
    Join Date
    06-05-2006
    Posts
    13

    quick question

    Hello,

    In Post #7, MSP gave me some great code which was quite advanced for me (I'm fairly new to VBA). I've since played/experimented/researched and now all of it makes sense. The only thing I don't understand is why these variables don't have to be declared:

    myColor = ws1.Cells(4, a + 1)
    myModel = ws1.Cells(b + 4, 1)

    Is this because myColor/myModel become strings? Or is this because we are using ws1?

    I would have thought I'd need to do something like:
    Dim myColor As String

    but my code works great w/o having to do that. Why?


    Thanks for your answer!
    michael

  6. #6
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by zasskar
    Hello,

    In Post #7, MSP gave me some great code which was quite advanced for me (I'm fairly new to VBA). I've since played/experimented/researched and now all of it makes sense. The only thing I don't understand is why these variables don't have to be declared:

    myColor = ws1.Cells(4, a + 1)
    myModel = ws1.Cells(b + 4, 1)

    Is this because myColor/myModel become strings? Or is this because we are using ws1?

    I would have thought I'd need to do something like:
    Dim myColor As String

    but my code works great w/o having to do that. Why?


    Thanks for your answer!
    michael
    Hi,

    as you do not have 'Option Explicit' at the start of your code page the code will define variables to suit.

    If you run with 'explicit' then you will need to define the variables x, myColor etc

    hth
    ---

  7. #7
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Good answer by Bryan already. Let me add 2 cents.

    I will almost always declare (dimension) objects because then the Intelli-sense kicks in ... so, as soon as I type a "." after the variable, a drop down box appears with all of the properties and methods for that object. It makes it a lot easier to code correctly.

    It is considered good form to always use Option Explicit. But, I guess I do not have good form.

  8. #8
    Registered User
    Join Date
    01-27-2010
    Location
    Alabama
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Custom message with mouseover

    Quote Originally Posted by MSP77079 View Post
    Hi Bryan,

    Haven't looked at the attachment yet. I am sure it is better than what I came up with.

    Meanwhile, Michael, here is what I came up with ... replace the code above with the code below (on the Pareto chart's code window). To use this, you need to have first created a shape (I chose a rectangle, but you can make it any auto shape you like) and Name it "CommentBox" (easiest way to do this is to use the Name box that is to the left of the Excel formula bar ... always remember to press Enter after typing in a name or the name will not "stick").

    Dim keepA As Long, keepB As Long
    
    Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim searchModel As Range, searchColor As Range
    Dim searchComment As Range, lastRow As Long
    Dim ID As Long, a As Long, b As Long
    Dim s As Series, p As Point
    Dim sh As Shape, strComment As String
        
        On Error GoTo leave
        Me.GetChartElement x, y, ID, a, b
        Set sh = Me.Shapes("CommentBox")
        Select Case True
            Case a = keepA And b = keepB
                'sh.Visible = False
            Case ID = 3
                Set ws1 = Sheet2
                myColor = ws1.Cells(4, a + 1)
                myModel = ws1.Cells(b + 4, 1)
                
                'do not need these, but this is what a & b represent:
                Set s = Me.SeriesCollection(a)
                Set p = s.Points(b)
    '            MsgBox WorksheetFunction.Index _
    '                    (Me.SeriesCollection(a).XValues, b)
    '            MsgBox WorksheetFunction.Index _
    '                    (Me.SeriesCollection(a).Values, b)
                    
                Set ws2 = Sheet3
                lastRow = ws2.Cells.SpecialCells(xlLastCell).Row
                
                Set searchModel = Range(ws2.Cells(1, 1), ws2.Cells(lastRow, 1))
                Set searchColor = Range(ws2.Cells(1, 2), ws2.Cells(lastRow, 2))
                Set searchComment = Range(ws2.Cells(1, 5), ws2.Cells(lastRow, 5))
    
                'MsgBox myColor, vbOKOnly, myModel
                For i = 1 To lastRow
                    If searchModel.Cells(i) = myModel Then
                        If searchColor.Cells(i) = myColor Then
                            strComment = vbLf & s.Name & vbLf
                            strComment = strComment & searchComment.Cells(i) & vbLf
                            With sh
                                .TextFrame.Characters.Text = strComment
                                .TextFrame.AutoSize = True
                                .Visible = True
                                'need to convert pixels to twips
                                'to get the Left & Top exactly right
                                .Left = x * 2 / 3
                                .Top = y * 2 / 3
                            End With
                            Exit For
                        End If
                    End If
                Next i
                'remember these so we do not keep doing the same thing
                'over and over again
                keepA = a
                keepB = b
            Case Else
                sh.Visible = False
                keepA = 0
                keepB = 0
        End Select
    
    leave:
    End Sub

    I know I am reviving a pretty old thread here, but this is exactly what I am trying to do except that I have my charts in a worksheet not in an individual "Chart" tab.

    The above code works perfectly for me when the chart is in its individual tab, but I have my charts in a worksheet and I am not sure how to get started with this? Any help would be greatly appreciated guys.

    (If it would be better for me to start a new thread instead of reviving an old identical one, let me know please and I can start a new thread)

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Custom message with mouseover

    Welcome to the forum, Sam.

    Please take a few minutes to read the forum rules, and then start your own thread. Also, please don't quote whole posts.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1