Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72

    Trying to control Internet Explorer in VBA

    Hi all. Some form of the Sendkeys command would be good, I think. I'm logging in fine but can't quite figure out how to click a tab on a tab control once I get in. Is there a special Sendkeys statement to do something like that? I've tracked down the ID of the tab but can't seem to make it work. The web page shows this in "Inspect Element" in Google Chrome. But I am using IE when I run the VBA code.

    Code:
    <li id="tab7" class="taboff" bar="/Reports/BarReports.jsp" onmouseover="highlight(this);" onmouseout="deHighlight(this);" onclick="select(this);">...</li>
    Thanks in advance... Glenn

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    What does "can't seem to make it work" mean? Error message, wrong results, nothing happens? Post code for analysis.

    Example from my db to execute web page button:

    Dim oBrowser As InternetExplorer
    Set oBrowser = New InternetExplorer
    ...
    oBrowser.Document.all.Item("Submit").Click

    Try "tab7" in place of "Submit"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Thanks June7,
    I will include my code here but it is standard VBA sendkeys stuff. And in response to your question, no, nothing happens. No error message, no erroneous data, and worst of all NO RESULTS. So nothing happens. It DOES appear to be a tab control on the web page but I say that because it looks like a tab control in VB(A). So am I saying it right?

    Code:
    Public Sub WebConnect()
    Dim IE As Object
        Set IE = CreateObject("InternetExplorer.Application")
        
        IE.navigate "http://www.somewebpage.com"
        IE.Visible = True
        
        While IE.busy
            DoEvents
        Wend
        IE.Document.all("loginId").Value = "user"
        IE.Document.all("password").Value = "Password"
        
        While IE.busy
            DoEvents
        Wend
        
        IE.Document.all.Item("btn").Click
        
        While IE.busy
            DoEvents
        Wend
        IE.Document.all.Item("tab7").Click
    End Sub[\code]
    Last edited by Glenn_Suggs; 09-16-2014 at 02:32 AM. Reason: i think the code END tag is wrong

  4. #4
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    But you get the picture...

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    The difference between your code and my code is .Item. I use that for the login and password lines as well.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    I'm now getting the error message: Run-time error '91': Object variable or With block variable not set.

    Do I need to set a reference to some object library?

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Yes. Look at:
    Microsoft Internet Controls
    Microsoft HTML Object Library

    I don't remember if both are needed but I have both selected.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    I also have both of those selected. I've researched some code and I am getting logged in by looking through the Element collection for the button to click, but I can't seem to find how to search for a tab control so that I can find which tab to click. That's on the first screen you get after logging in and the View Source shows the code that I put in my first post. It goes like this:
    <li id="tab7" class="taboff" bar="/Reports/BarReports.jsp" onmouseover="highlight(this);" onmouseout="deHighlight(this);" onclick="select(this);">...</li>

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Sorry, never needed to and never tried to reference tab on web page. Are you sure that is necessary? Can't just reference the other controls directly regardless of which 'tab' they are on?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Hello again. I tried to reference the button after logging in and it can't find the one I need. It seems to be on one of several frames but I'm not sure how to code this to point to the correct frame. I do have the name of the frame. Any ideas?
    Thanks... Glenn

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    Post #4 looks like it might fit the bill but I guess my syntax is off or something. My login controls are not on the frame but the first page AFTER logging in does have the frames. The example in the post looks like it uses an index (0) for the frame but how can I find out that information on the page in my particular case. I am talking about the line that goes:
    [IE].Document.frames(0).Document.all.Item("Button_to_C lick").Click ... I can't find a reference in the HTML to an index for the frames. I also have tried using Inspect Element in Google Chrome and still can't get the VBA to recognize what I'm trying to do.

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is a code snippet I created for logins. Notice that the main doc loading does not guarantee that all of the frames have finished loading.


    Code:
    Dim strAddress As String
    Dim appInternet As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    
    strAddress = "http://www.SomeWebsite.com/login"
    Set appInternet = CreateObject("InternetExplorer.Application")
    
        With appInternet
        
          .navigate strAddress
          .Visible = True
          While .ReadyState <> 4 Or .Busy = True: Wend
          Set HTMLdoc = .Document
    
        End With
    
    Dim docFrame1 As HTMLDocument
    Set docFrame1 = HTMLdoc.frames(2).Document
    
    While docFrame1.ReadyState <> 4 Or .Busy = True: Wend
    
    docFrame1.getElementById("logInName").Value = "Login"
    docFrame1.getElementById("password").Value = "Pass"
    docFrame1.Forms(0).submit

  14. #14
    Glenn_Suggs is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2012
    Posts
    72
    How did you know to use index (2) on the line: Set docFrame1 = HTMLdoc.frames(2).Document?

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Glenn_Suggs View Post
    How did you know to use index (2) on the line: Set docFrame1 = HTMLdoc.frames(2).Document?
    I use temp code to iterate each parent node and enumerate its children. Sometimes you can look at the HTML and guess. If you look at my example, you can see the use if ID tags ("logInName" and "password"). Those are obvious. What is not so obvious are the indexes for frames, forms, tables, etc. For these nodes, I will iterate using a For Each or for I = 0 Until, counting each node. For really complex HTML, I will employ a nested for each. I may debug.print the results or write the results to a text file.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Internet Explorer Print Specific Page
    By luckasx in forum Access
    Replies: 10
    Last Post: 12-03-2013, 09:10 AM
  2. Find Internet Explorer window based on specific site
    By redbull in forum Code Repository
    Replies: 0
    Last Post: 04-02-2013, 09:19 AM
  3. VBA > Internet Explorer
    By Stokecpa in forum Programming
    Replies: 3
    Last Post: 08-06-2012, 01:10 AM
  4. File Explorer in VBA
    By ybg1 in forum Programming
    Replies: 6
    Last Post: 02-06-2012, 03:55 PM
  5. Internet Explorer automation with VBA
    By sa230e in forum Programming
    Replies: 0
    Last Post: 09-29-2011, 05:04 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums