Hi Nick,
Your solution is very elegant. All I had to add was to set the label border
style to 1 (single line) so I could see the lines. It does exactly what I
asked. (Single one).
What I am actually trying to do is add cross hairs to an IE object set with
the following code.
The Addlabel dies at runtime with “Run time error Invalid class stringâ€
which I think is due to the “ ie.label.lblHoriz†not being the correct way to
add a label control to the IE object. I don’t know what would be correct.
Also I don’t know how to make the correct event handler for the mouse move
event while the mouse is on the IE form.
Any ideas?
Dim ie as Object
Sub Addlabel(strControl As String, intLeft As Integer, intTop As Integer,
intWidth As Integer, intHeight As Integer, strCaption As String)
Dim mycmd As Control
Set mycmd = Controls.Add(strControl)
mycmd.Left = intLeft
mycmd.Top = intTop
mycmd.Width = intWidth
mycmd.Height = intHeight
mycmd.BorderStyle = 1
If strCaption <> "" Then
mycmd.Caption = strCaption
End If
mycmd.Visible = True
End Sub
'
' not sure about this
'
Private Sub ie_MouseMove(ByVal Button As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)
lblHoriz.Top = Y
lblVert.Left = X
End Sub
Private Sub UserForm_Initialize()
With lblHoriz
.Height = 1
.Left = 0
.Width = Me.Width
End With
With lblVert
.Width = 1
.Top = 0
.Height = Me.Height
End With
set ie = CreateObject("InternetExplorer.Application")
ie.AddressBar = False
ie.MenuBar = False
ie.Toolbar = False
ie.Width = 600
ie.Height = 750
ie.Left = 0
ie.Top = 0
ie.navigate "
www.yahoo.comâ€
With ie
While Not .readyState = READYSTATE_COMPLETE
DoEvents
Wend
‘ I can control scroll bars with:
..document.parentWindow.Scroll 100, 200
..Visible = True
‘Add cross hairs here --NOT CORRECT
Call UserForm1.Addlabel( "ie.label.lblHoriz",2, 10, 175, 20, "")
Call UserForm1.Addlabel( " ie.label.lblVert",2, 20, 175, 20, "")
..end with