+ Reply to Thread
Results 1 to 3 of 3

VBA draw and erase lines (crosshairs) on form

  1. #1
    gary
    Guest

    VBA draw and erase lines (crosshairs) on form

    Using VBA, I need to create full form crosshairs that will extend to the top
    and sides of the form. When the user moves the mouse the crosshairs move
    with it making it easy to see labels at the bottom and side of the form. I
    have had no success in doing this. Also the graphic on the form needs to not
    be disturbed.

    Thanks for your help,

    Gary


  2. #2
    Greg Wilson
    Guest

    RE: VBA draw and erase lines (crosshairs) on form

    If you mean a worksheet based "form" then getting a worksheet to recognize
    the Mouse_Move event and to drag crosshairs is very technically challenging
    and at the same time, from what I recollect, problematic. Instead, if
    acceptable, I suggest adapting Bob Phillip's post from the following thread.
    Note also Robert McCurdy's post:

    http://tinyurl.com/m3gs7

    I append my suggested adaption of Bob's post. Assumed is that the form area
    is within the range "B2:Z30". For the demo, I advise making column widths and
    row heights equal and giving the range an interior colour, say gray. Note
    that the highlighting is not affected by selecting multiple cells within the
    form area or selecting outside of the form area.

    Paste to the worksheet code module:-

    Const HLColor As Long = 13434879

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim r As Range, rcol As Range, rrow As Range
    Set r = Me.Range("B2:Z30")
    If Intersect(Target, r) Is Nothing Then Exit Sub
    Set rcol = Intersect(r, Target.EntireColumn)
    Set rrow = Intersect(r, Target.EntireRow)
    With Target
    If .Count > 1 Then Exit Sub
    r.FormatConditions.Delete
    With rrow
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    .FormatConditions(1).Interior.Color = HLColor
    End With
    With rcol
    .FormatConditions.Delete
    .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    .FormatConditions(1).Interior.Color = HLColor
    End With
    .FormatConditions.Delete
    End With
    End Sub

    Regards,
    Greg


    "gary" wrote:

    > Using VBA, I need to create full form crosshairs that will extend to the top
    > and sides of the form. When the user moves the mouse the crosshairs move
    > with it making it easy to see labels at the bottom and side of the form. I
    > have had no success in doing this. Also the graphic on the form needs to not
    > be disturbed.
    >
    > Thanks for your help,
    >
    > Gary
    >


  3. #3
    gary
    Guest

    RE: VBA draw and erase lines (crosshairs) on form

    Greg,

    I do not mean a worksheet based form. I am actually from Excel using VBA to
    launch an IE browser that will then go to a web site to display a chart.
    From this browser window, I want the cursor when it is in this window to
    change to entire window cross hairs so I can accurately read the numbers at
    the ends of the browser window. My problem is how to turn the mouse cursor
    into cross hairs that extend to the ends of the browser window and then be
    able to move the mouse around this window without disturbing the chart on the
    window.

    I hope that makes more sense.

    Thanks for your help,

    Gary


    "Greg Wilson" wrote:

    > If you mean a worksheet based "form" then getting a worksheet to recognize
    > the Mouse_Move event and to drag crosshairs is very technically challenging
    > and at the same time, from what I recollect, problematic. Instead, if
    > acceptable, I suggest adapting Bob Phillip's post from the following thread.
    > Note also Robert McCurdy's post:
    >
    > http://tinyurl.com/m3gs7
    >
    > I append my suggested adaption of Bob's post. Assumed is that the form area
    > is within the range "B2:Z30". For the demo, I advise making column widths and
    > row heights equal and giving the range an interior colour, say gray. Note
    > that the highlighting is not affected by selecting multiple cells within the
    > form area or selecting outside of the form area.
    >
    > Paste to the worksheet code module:-
    >
    > Const HLColor As Long = 13434879
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Dim r As Range, rcol As Range, rrow As Range
    > Set r = Me.Range("B2:Z30")
    > If Intersect(Target, r) Is Nothing Then Exit Sub
    > Set rcol = Intersect(r, Target.EntireColumn)
    > Set rrow = Intersect(r, Target.EntireRow)
    > With Target
    > If .Count > 1 Then Exit Sub
    > r.FormatConditions.Delete
    > With rrow
    > .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    > .FormatConditions(1).Interior.Color = HLColor
    > End With
    > With rcol
    > .FormatConditions.Delete
    > .FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    > .FormatConditions(1).Interior.Color = HLColor
    > End With
    > .FormatConditions.Delete
    > End With
    > End Sub
    >
    > Regards,
    > Greg
    >
    >
    > "gary" wrote:
    >
    > > Using VBA, I need to create full form crosshairs that will extend to the top
    > > and sides of the form. When the user moves the mouse the crosshairs move
    > > with it making it easy to see labels at the bottom and side of the form. I
    > > have had no success in doing this. Also the graphic on the form needs to not
    > > be disturbed.
    > >
    > > Thanks for your help,
    > >
    > > Gary
    > >


+ Reply to 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