+ Reply to Thread
Results 1 to 8 of 8

Manipulating Dropdown List in IE using VBA & Form Submit oddities

Hybrid View

  1. #1
    Registered User
    Join Date
    01-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    5

    Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Hello Excel gurus! I could use your assistance on something that's perplexed me for a bit. Got two issues if that's fine.

    First issue: I have a form I am trying to manipulate in VBA. Form is at http://douglasne.mapping-online.com/.../valuation.jsp . Basically I am running into an issue trying to manipulate the dropdown menus. Here is my code:


        IE.Navigate "http://douglasne.mapping-online.com/DouglasCoNe/static/valuation.jsp"
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
       On Error GoTo 0
            Dim j As Integer
        
    
        Set FormBar = IE.Document.Forms(0)
    
        Dim Dir As String
        Dim Street As String
        Dim Ave As String
    
        Number = Cells(i, 1).Value
        If Cells(i, 2).Value = "N" Or Cells(i, 2).Value = "S" Or Cells(i, 2).Value = "E" Or Cells(i, 2).Value = "W" Then
        Dir = Cells(i, 2).Value
        Street = Cells(i, 3).Value
        Else
        Dir = ""
        Street = Cells(i, 2).Value
        
        End If
        With FormBar
    
    
        FormBar(2).Value = Number
        FormBar(3).Value = S
        IE.Document.Forms(0).getElementsByTagName("select")("StreetDir").Value = "S"
        FormBar(4).Value = Street
        IE.Document.Forms(0).Item("StreetSfx").Value = "Av"
        FormBar.submit
    It correctly fills in the "house #" and "Street Name" correctly, but despite what I have tried (directly referring to the elements, which I believe are 3 and 5, or "StreetDir and StreetSfx" I just cannot get it to change the values from blank! Any ideas or tips on how to get it to work, please? Thanks in advance!

    Problem #2:

    Different form, with a weird oddity. So the form is at http://www.sarpy.com/sarpyproperty/ . My code is as follows:

        IE.Navigate "http://www.sarpy.com/sarpyproperty/"
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
       On Error Resume Next
            Dim j As Integer
        
    
        Set FormBar = IE.Document.Forms(0)
    
        Dim Dir As String
        Dim Street As String
        Dim Ave As String
    
      
     
        With FormBar
    
    On Error GoTo 0
        FormBar(9).Value = Street
        FormBar(10).Value = Street
        'Application.SendKeys "( )"
        'AppActivate ("IE")
      'Application.SendKeys "{Enter}"
       On Error Resume Next
        FormBar.sumbit
    So it fills in the inputs correctly. However, here's the oddity:

    If I click on the "submit" button manually in IE, it submits the form. If I have VBA run the submit function OR click the button, it just goes back to the main screen. I don't get it. Anyone got any ideas?

    Thanks so much!!!!!!!!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Where's the rest of the code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Here is the rest of the code for the first. Getting the second code in a minute. It's kinda sloppy but I've had to make do with a semi-automatic version that required some manual input. My client wants it fully automated though!

    Sub RunModel()
    
        Application.DisplayAlerts = False
    
    
    
    
    
        Dim IE As Object
        Dim LogIn As Variant
        Dim ProcessComplete As Boolean
        Set IE = CreateObject("InternetExplorer.Application") ' Open Office
        'LogIn = MsgBox("Did you log into Skynet with Internet Explorer?", vbYesNo)
    
    
        'Date Stuff
    
    
    
        '------------------------Arrival Data-----------------
        'Go to this Web Page!
        Dim i As Integer
        i = 2
        Dim Ticker As String
        For i = 2 To 429
        IE.Navigate "http://douglasne.mapping-online.com/DouglasCoNe/static/valuation.jsp"
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
       On Error Resume Next
            Dim j As Integer
        
    
        Set FormBar = IE.Document.Forms(0)
    
       ' If FormBar Is Nothing Then
       ' Exit Sub
       ' End If
        Dim Dir As String
        Dim Street As String
        Dim Ave As String
    
        Number = Cells(i, 1).Value
        If Cells(i, 2).Value = "N" Or Cells(i, 2).Value = "S" Or Cells(i, 2).Value = "E" Or Cells(i, 2).Value = "W" Then
        Dir = Cells(i, 2).Value
        Street = Cells(i, 3).Value
        Ave = Cells(i, 4).Value
        Else
        Dir = ""
        Street = Cells(i, 2).Value
        Ave = Cells(i, 3).Value
        End If
        Select Case Ave
        Case "Street"
        Ave = "ST "
        Case "Avenue"
        Ave = "AV"
        Case "Drive"
        Ave = "DR"
        Case "Circle"
        Ave = "CR"
        Case "Boulevard"
        Ave = "BLVD"
        Case Else
        Ave = ""
        End Select    
    
    
        End If
        With FormBar
    
    
        FormBar(2).Value = Number
        FormBar(3).Value = Dir
        FormBar(4).Value = Street
        FormBar(5).Value = Ave
    
        FormBar.submit
           On Error GoTo 0
                    
    Cells(i, 7) = IE.Document.getElementbyId("results").Cells(5).innertext
    
    
        On Error GoTo 0
    
     
        Next i
     
    
        
    End Sub


    Edit: I'm super sorry but the select case part that defined Ave is missing in some code somewhere. Trust me, there is a definition for it. The variables themselves are fine (at least they are defined) but they won't input into the forms. I know my code is an absolute mess but I have been toying with it for hours and I just cannot get these dumb forms to accept ANYTHING!

    Edit #2: Found the avenue piece. I will update with code 2 in a minute.
    Last edited by JScottArnold; 01-30-2013 at 05:20 PM. Reason: forgot to end code tag

  4. #4
    Registered User
    Join Date
    01-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Here is the full second problem code:

    Sub RunSarpyModel()
    
        Application.DisplayAlerts = False
    
        Dim IE As Object
        Dim LogIn As Variant
        Dim UserName As String, Password As String
        Dim ProcessComplete As Boolean
        Set IE = CreateObject("InternetExplorer.Application") ' Open IE
    
    
        'Go to this Web Page!
        Dim i As Integer
        Dim Account As Variant
        i = 3
        Dim Ticker As String
        For i = 3 To 117
        IE.Navigate "http://www.sarpy.com/sarpyproperty/"
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
       On Error Resume Next
            Dim j As Integer
        
    
        Set Formbar = IE.Document.Forms(0)
    
       ' If FormBar Is Nothing Then
       ' Exit Sub
       ' End If
        Dim Dir As String
        Dim Street As String
        Dim Ave As String
    
        Street = Cells(i, 6).Value
    
          
     
        With Formbar
    
    On Error GoTo 0
        Formbar(9).Value = Street
        Formbar(10).Value = Street
    
      On Error Resume Next
        Formbar(11).Click
    
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
        
        
        Addy = Cells(i, 5).Value
        
      Account = IE.Document.all.Item(136).innerText
      Account = Left(Account, 9)
        IE.Navigate "http://www.sarpy.com/sarpyproperty/pdisplay3.aspx?locid=" & Account
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
    Dim test As Variant
        Cells(i, 14) = IE.Document.all.Item(51).innerText
        Cells(i, 15) = IE.Document.all.Item(59).innerText
        Cells(i, 16) = IE.Document.all.Item(62).innerText
    
    
        End With
    
    
        On Error GoTo 0
    
    
      
    
        
    End Sub
    Hopefully this helps. Again I apologize, I've been hacking at this code way too much to make it work but I've tried everything I can think of and some google searches. If you can help I would be so thankful!!!!

    Edit: Cleaned it up some. Let me know if I can do anything else to help!
    Last edited by JScottArnold; 01-30-2013 at 05:26 PM.

  5. #5
    Registered User
    Join Date
    01-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Whoops, had some internet issues and double posted.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    This is how you can select from the Suffix dropdown.
              FormBar("StreetSfx").selectedindex = 12

  7. #7
    Registered User
    Join Date
    01-30-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    Quote Originally Posted by Norie View Post
    This is how you can select from the Suffix dropdown.
              FormBar("StreetSfx").selectedindex = 12
    Fantastic! That worked perfectly! Thank you so much!

    Edit: I'll clean up the second code so it compiles. I needed to make it actually look halfway decent anyway.

    Edit #2: Here is the code. I accidentally deleted a next i.

    Sub RunSarpyModel()
    
        Application.DisplayAlerts = False
    
    
    
    
    
        '-------This Works----------
        Dim IE As Object
        Dim ProcessComplete As Boolean
        Dim NumEntries As Integer
        Set IE = CreateObject("InternetExplorer.Application") ' Open Office
    
    
    
        'Go to this Web Page!
        Dim i As Integer
        Dim Account As Variant
        ' Find number of Properties
        Dim Ticker As String
        For i = 2 To 117
        
        'Navigate to Sarpy
        IE.Navigate "http://www.sarpy.com/sarpyproperty/"
        'Wait
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
        
        
        On Error Resume Next
        Dim j As Integer
        
    
        Set FormBar = IE.Document.Forms(0)
    
       ' If FormBar Is Nothing Then
       ' Exit Sub
       ' End If
        Dim Dir As String
        Dim Street As String
        Dim Ave As String
    
        Street = Cells(i, 6).Value
    
          
     
        With FormBar
    
        On Error GoTo 0
        FormBar(9).Value = Street
        FormBar(10).Value = Street
    
        FormBar(11).Click
        
        End With
    
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
        
        On Error Resume Next
        
        Addy = Cells(i, 5).Value
        
      Account = IE.Document.all.Item(136).innertext
      Account = Left(Account, 9) 'Get Account #
      
      'Let IE do it's thing
        IE.Navigate "http://www.sarpy.com/sarpyproperty/pdisplay3.aspx?locid=" & Account
        Do
        If IE.ReadyState = 4 Then
        IE.Visible = True
        Exit Do
        Else
        DoEvents
        End If
        Loop
    Dim test As Variant
        Cells(i, 14) = IE.Document.all.Item(51).innertext
        Cells(i, 15) = IE.Document.all.Item(59).innertext
        Cells(i, 16) = IE.Document.all.Item(62).innertext
    
    
    
    
        On Error GoTo 0
    
    Next i ' Next Entry
    
        
    
        
    End Sub
    Thanks for your patience!
    Last edited by JScottArnold; 01-30-2013 at 05:46 PM.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Manipulating Dropdown List in IE using VBA & Form Submit oddities

    I'm sorry but that code doesn't compile.

+ 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