1819
03-09-2017, 08:03 PM
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
<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.
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
<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.