Consulting

Results 1 to 8 of 8

Thread: Runtime 91 error on userform populating one input box on webpage

  1. #1
    VBAX Regular
    Joined
    Oct 2014
    Posts
    95
    Location

    Runtime 91 error on userform populating one input box on webpage

    I simply need to use VBA to replicate the manual process of entering data into an input box on a webpage and clicking return.

    The code I have is below. It is returning a runtime error 91 at the line shown.

    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Sub CommandButton1_Click()
        Dim ws As Worksheet
        Dim url As String
        Dim lastRow As Long
    
        url = "https://twitrss.me/"
    
        '~~> This is the sheet where the values has to be picked up from
        Set ws = Sheets("RSSTwitMe")
    
        With ws
            '~~> Get the Last Row in Sheet1
            lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            '~~> Loop through the range
            For i = 1 To lastRow
                '~~> Navigate to the URL
                WebBrowser1.Navigate url
                WaitForWBReady
    
                '~~> Input Values
                WebBrowser1.Document.getElementById("screen_name").Value = .Range("A" & i).Value
               
                '~~> Click Button
                WebBrowser1.Document.getElementsByTagname("fetch")(2).Click '<<<<<<<<<<<<<<<<RUNTIME ERROR 91
    
                WaitForWBReady
            Next
        End With
    End Sub
    
    Private Sub Wait(ByVal nSec As Long)
        nSec = nSec + Timer
        While Timer < nSec
            DoEvents
            Sleep 100
        Wend
    End Sub
    
    Private Sub WaitForWBReady()
        Wait 1
        While WebBrowser1.ReadyState <> 4
            Wait 3
        Wend
    End Sub
    I understand that this is usually caused because the VBA code does not match the code of the web page.

    So I have also included below the code from the website showing the relevant section in HTML

    HTML Code:
    <div class="container">
    <h1>TwitRSS.me</h1>
    <h2>Get your twitter user feed as RSS</h2>
    <p> </p>
    <form method="get" action="/twitter_user_to_rss/">
    <label for="screen_name">Twitter User:</label>
    <br>
    @
    <input id="screen_name" class="input" type="text" placeholder="ciderpunx" value="" size="20" maxlength="140" name="user">
    <br>
    <label for="replies">With replies?:</label>
    <input id="replies" type="checkbox" style="margin-left:1.2em" name="replies">
    <br>
    <label class="hid" for="submit">   </label>
    <input id="fetch" class="btn btn-primary btn-lg" type="submit" value=" Fetch RSS ">
    </form>
    <p></p>
    <h2 style="padding-top:2em">
    <form method="get" action="/twitter_search_to_rss/">
    <p></p>
    </div>
    </div>
    <div class="container">
    <div class="container-alternate">
    <footer>
    <script src="//code.jquery.com/jquery-1.10.2.min.js">
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js">
    <script>
    <script type="text/javascript">
    <div class="igtranslator-main-div" style="display: none; width: 0px; height: 0px;">
    <div class="igtranslator-activator-icon bounceIn" style="background-image: url("resource://jid1-dgnibwqga0sibw-at-jetpack/data/icons/home.png"); display: none;" title="Click to Show Translation"></div>
    <div class="SnapLinksContainer" style="margin-left: 0px; margin-top: 0px; display: none;">
    </body>
    Finally, I will try to attach a small sample worksheet but at present VBA Express is not working properly to accept it.

    Please help make this work. Many thanks.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Regular
    Joined
    Oct 2014
    Posts
    95
    Location

    Excellent link.. but still looking for direct answer to the question

    Thanks for this link - it will be really useful - but I am still looking for a direct answer to my problem in the original post.

    The macro I am trying to fix allows tweets to be collected in an RSS feeder and then stored or used for analysis.

    So it's no about transmitting tweets.

    Thanks again.

  4. #4
    VBAX Regular keebellah's Avatar
    Joined
    May 2011
    Location
    The Netherlands
    Posts
    19
    Location
    The message is "Object Variable not set" I suggest you step through the code and check the line where it happens
    Cheers,
    Hans
    "May the code be with you ... If it isn't... start debugging!"
    www.hcandts.com

  5. #5
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    adopt below code.
    worked for me.

    Sub vbax_58828_click_button_web_page()
    
        Dim v_elements, v_ele
        
        With CreateObject("InternetExplorer.application")
            .Visible = True
            .Navigate "https://twitrss.me/"
            
            Do Until .ReadyState = 4
                DoEvents
            Loop
        
            .Document.getElementById("screen_name").Value = "TwitterUserNameHere"
            
            Set v_elements = .Document.getElementsByTagName("input")
            For Each v_ele In v_elements
                If v_ele.getAttribute("value") = " Fetch RSS " Then
                     v_ele.Click
                    Exit For
                End If
            Next v_ele
            
            Do Until .ReadyState = 4
                DoEvents
            Loop
        End With
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  6. #6
    VBAX Regular keebellah's Avatar
    Joined
    May 2011
    Location
    The Netherlands
    Posts
    19
    Location
    @mancubus: worked for me too, nice one
    Cheers,
    Hans
    "May the code be with you ... If it isn't... start debugging!"
    www.hcandts.com

  7. #7
    VBAX Regular
    Joined
    Oct 2014
    Posts
    95
    Location

    Many thanks - but I have jsut found it needs to use Firefox not IE

    Quote Originally Posted by mancubus View Post
    adopt below code.
    worked for me.

    Sub vbax_58828_click_button_web_page()
    
        Dim v_elements, v_ele
        
        With CreateObject("InternetExplorer.application")
            .Visible = True
            .Navigate "https://twitrss.me/"
            
            Do Until .ReadyState = 4
                DoEvents
            Loop
        
            .Document.getElementById("screen_name").Value = "TwitterUserNameHere"
            
            Set v_elements = .Document.getElementsByTagName("input")
            For Each v_ele In v_elements
                If v_ele.getAttribute("value") = " Fetch RSS " Then
                     v_ele.Click
                    Exit For
                End If
            Next v_ele
            
            Do Until .ReadyState = 4
                DoEvents
            Loop
        End With
    
    End Sub
    Thanks @mancubus for this - really helpful. I've just found that the macro needs to use Firefox because the information inputted is used by a Firefox extension. How would the code adapt to work in Firefox? Thanks.

  8. #8
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    you are welcome.

    pls dont quote the previous messages and codes as a whole. refer to the parts where necessary.

    i am not sure if this can be done via Firefox or Chrome.

    this may give you an ides.

    http://www.makeuseof.com/tag/how-to-...-and-selenium/
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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