Control page InternetExplorer-VBForums
Results 1 to 9 of 9

Thread: Control page InternetExplorer

  1. #1

    Thread Starter
    Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    49

    Control page InternetExplorer

    Please Help

    How this code works


    Dim WithEvents Web As SHDocVw.InternetExplorer
    Dim WithEvents HTMLdoc As HTMLDocument


    Private Sub Command1_Click()

    Set Web = CreateObject("InternetExplorer.Application")

    Web.Visible = True
    Web.navigate App.Path & "\index.htm"

    End Sub
    Private Function HTMLdoc_onclick() As Boolean
    On Error Resume Next

    If HTMLdoc.activeElement.id = "mo" Then
    MsgBox ""
    Else

    End If

    End Function

    Private Sub Web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    On Error Resume Next
    If Not Web.document Is Nothing Then

    Set HTMLdoc = Web.document

    Else

    End If
    End Sub

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    608

    Re: Control page InternetExplorer

    K

    Two suggestions:

    1. When you post code, use the CODE wrapper .. it is the # on the menu bar
    Code:
    Dim WithEvents Web As SHDocVw.InternetExplorer
    Dim WithEvents HTMLdoc As HTMLDocument
    
    
    Private Sub Command1_Click()
        Set Web = CreateObject("InternetExplorer.Application")
        Web.Visible = True
        Web.navigate App.Path & "\index.htm"
    End Sub
    
    Private Function HTMLdoc_onclick() As Boolean
        On Error Resume Next
        If HTMLdoc.activeElement.id = "mo" Then
            MsgBox ""
        Else
            '
        End If
    End Function
    
    Private Sub Web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        On Error Resume Next
        If Not Web.document Is Nothing Then
            Set HTMLdoc = Web.document
        Else
            '
        End If
    End Sub
    .. and provide indents to make it easier to read,

    2. Could you expand your question a bit more
    • what don't you understand?
    • what is it that you want to accomplish?


    Spoo

  3. #3

    Thread Starter
    Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    49

    Re: Control page InternetExplorer

    The button "mo" is required when you open the Web page

  4. #4
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    608

    Re: Control page InternetExplorer

    K

    Sorry, I'm lost.

    1. I did not try your code in a project, I just repeated it in post #2 for display purposes
    2. Your post #2 is a statement, not a question.
    • What have you tried?
    • What parts work?
    • What parts don't work?


    Maybe you could include a screen-shot.

    Spoo

  5. #5

    Thread Starter
    Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    49

    Re: Control page InternetExplorer

    This does not work


    Code:
    Private Function HTMLdoc_onclick() As Boolean
        On Error Resume Next
        If HTMLdoc.activeElement.id = "mo" Then
            MsgBox ""
        Else
            '
        End If
    End Function

  6. #6
    Addicted Member
    Join Date
    Apr 2017
    Posts
    163

    Re: Control page InternetExplorer

    Your code works exactly as is if you

    1) add Microsoft HTML Object Library to your project

    2) add Microsoft Internet Controls to your project

    and

    3) index.htm has a button with an id="mo"

  7. #7

    Thread Starter
    Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    49

    Re: Control page InternetExplorer

    Yes there is a button mo in index.htm

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    22,801

    Re: Control page InternetExplorer

    are you clicking on the page?
    does the on_click event fire at all?
    do you get the message box?
    if the on_click fires and no message box, has an error occurred? or what is supposed to happen?
    can you tell if an error has occurred?
    is mo likely to be the active element or is some focus change occurring?

    remove oern to see if that changes anything
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    Addicted Member
    Join Date
    Apr 2017
    Posts
    163

    Re: Control page InternetExplorer

    OP shouldn't have a problem. I already said in post 5 all he has to do is to add the references and make sure his document contains a button with id of "mo"

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.