+ Reply to Thread
Results 1 to 7 of 7

Internet Explorer interation

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Internet Explorer interation

    I have an online form that I need to frequently populate from an excel spreadsheet, on the first page is a drop down box where I would normally select a category from. Why I click the category using the mouse it automatically advances me through to the next page, however when I use the macro below to do it, whilst the box shows the correct category, the page is not advanced. Can you help me?

    Sub DropDown()
    
        Dim ie As InternetExplorer
    
        Set ie = New InternetExplorer
        ie.Visible = True
        ie.Navigate "http://MYSITE/choose_cat.php"
    
        Do Until ie.ReadyState = READYSTATE_COMPLETE
        Loop
    
        ie.document.forms(1).Item("catid").Value = "28"
       
    End Sub
    As a bit of further information this is how the website deals with the box being changed (I don't understand it!):

    <select name="catid" onchange="checkSelectedOption(this.value, document.add_ad,'Categories marked with *.');">
    Last edited by ChrisMattock; 05-10-2012 at 03:44 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Internet Explorer interation

    Try clicking the Select element or firing its onChange event:
    ie.document.forms(1).Item("catid").Click
    'Or
    ie.document.forms(1).Item("catid").FireEvent "onChange"
    You will need an ie.ReadyState wait loop after this.
    Post responsibly. Search for excelforum.com

  3. #3
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Re: Internet Explorer interation

    Chippy - you're a star... the FireEvent line worked perfectly!

  4. #4
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Re: Internet Explorer interation

    Thanks for helping with my problem, if you don't mind me asking I just have one more problem... on the next page I need to get the VB to click a link - no button unfortunately - the code just looks like this:

    <a href='http://www.mysite.com/upload_file.php?pic_cat_id=322207'>
    Upload Picture</a>

    Unfortunately the URL changes depending on the entry number, so I need to click the link rather than going to a generic URL. Can you help? I don't know how to select and click that link?

  5. #5
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Internet Explorer interation

    Get a reference to the link (HTMLAnchorElement). One way is by looping through IE.Document.links, looking for the link with innerText = "Upload Picture", or href containing part of the URL, e.g. "www.mysite.com/upload_file" (use Instr function). Once you have the reference, click it using:

    theLink.Click

  6. #6
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Re: Internet Explorer interation

    Thanks, but could you be more specfic as to how to do that? I don't seem to be able to get it to work. I tried the following - sorry, I'm really rusty on all this, I'm sure I'm completely wrong:

        For Each ieForm In ie.document.forms
            If InStr(ieForm.innertext, "Upload Picture") <> 0 Then
            ULogin = True
            ieForm.Click
            Exit For
            Else
            End If
        Next

  7. #7
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Internet Explorer interation

    IE.Document.links, not IE.Document.forms! Try this:
        Dim link As Object
        
        For Each link In IE.document.Links
            If link.innerText = "Upload Picture" Then
                link.Click
                Exit For
            End If
        Next

+ 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