Scrape data from ajax loaded table into excel using VBA - ajax

I've got a problem with one case that I want to resolve.
I've a web-page with 3 tables that are loaded by clicking the button (ajax response). User is selecting the date ranges and after button is clicked data is populated to tables.
What I want to do is to take those tables into excel using VBA, so within one click I can copy those tables from page to excel.
I've searched the internet, but didn't found something that regards to similar issue.
Currently I've macro to download those tables, but by default they are empty, so the code downloads only headers.
Option Explicit
Sub GetData()
Dim H As Object, B$, D As Object, C As Object
Set C = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
Set D = CreateObject("HTMLFile")
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
H.SetAutoLogonPolicy 0
H.Open "GET", "https://mywebpage.com"
H.Send
D.body.innerHTML = H.ResponseText
C.SetText D.getElementById("table").outerHTML
C.PutInClipboard
Worksheets("sheet1").[A1].PasteSpecial
Worksheets("sheet1").Cells.Hyperlinks.Delete
End Sub
Does anyone have some idea how to call ajax function (with time parameters that are chosen in the page) from the excel visual basic?

Related

How to get content from field

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.
so the database looks like this.
ID_ZIP ZIP CITY
1 97425 Les Avirons
2 82289 Toto
In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.
So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.
I tried this
Sub getZip
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"
End Sub
But it returns an error on the Toto = Form.GetByName("ZipCode") line.
The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:
Create Form in Design View
Use the List Box tool (is that what you mean by "select"?) and create a control.
Cancel out of the wizard if it pops up.
Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
Set the Name to "ZipCode" (without quotes).
Save and close the form.
Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.
A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.

Does a VBA module in Excel treated as a spreadsheet in NPOI or POI?

I am working on a NPOI project.
I have an Excel file which contains 5 spread sheets out of which:
2 are hidden (as they are dialog, user interface, kind of sheets DlgView1, DlgView2).
3 work sheets (WrkSht1, WrkSht2, WrkSht3) are visible with some data containing formulas and external links.
Also, the Excel sheet contains a VBA module called Module1.bas with some logic.
When I check the number of worksheets using workbook.NumberOfSheets property, it shows 5, but when I iterate through the code for all worksheets present, I get the below results:
1. Sheet1 = DlgView1 -------> which is hidden
2. Sheet2 = DlgView2 -------> which is hidden
3. Sheet3 = Module1 -------> which is hidden --->This is what is confusing!!!!
4. Sheet4 = WrkSht1 -------> which is visible
5. Sheet5 = WrkSht2 -------> which is visible
It should have been like this instead I suppose:
1. Sheet1 = DlgView1 -------> which is hidden
2. Sheet2 = DlgView2 -------> which is hidden
3. Sheet3 = WrkSht1 -------> which is visible
4. Sheet4 = WrkSht2 -------> which is visible
5. Sheet5 = WrkSht3 -------> which is visible
I cannot get access to one of the visible worksheet WrkSht3 as the count(= 5) of worksheet ends by this time.
Also, when my code sets to play around different cells of worksheet WrkSht1, it will actually be pointing to WrkSht2 and for worksheet WrkSht2, it will actually be pointing to WrkSht3.
But WrkSht3 was never initialzed as a worksheet as seen from the above results.
For testing purpose, I deleted Module1 and checked, it works fine with count as 5 and considering all the worksheets (DlgView1, DlgView2, WrkSht1, WrkSht2, WrkSht3) to process.
Also, to mention, I get an exception thrown while working with this file & not with any others:
Unsupported BOF found of type VBModule
My question is:
Does NPOI or POI treat a VBA module in a Excel sheet as a hidden worksheet?
If not, why is the code considering Module1 as worksheet and not the actual visible worksheet WrkSht3 as explained above.
If yes, is there a way to tell code not consider VBA Modules as worksheets and also actual visible worksheets like WrkSht3.
If needed, I can send the Excel sheet which I am working on. Thanks

unable to save changes in our web application when running VB test script using testcomplete 11.0

I have Recorded a VB test script in TestComplete 11.0 and did some changes in our web application. when i was running the recorded test script, i didnt get any errors in log file which was generated by TestComplete but changes are not reflecting in our application.
Here is the VB Test Script:
Sub Test1
Dim browser
Dim page
Dim form
Dim textbox
Dim table
TestedApps.XXXcm.Run
Call Browsers.Item(btIExplorer).Navigate("http://localhost/XXXcm/connect.asp")
Set browser = Aliases.browser
Set page = browser.pageXXXConfigurationManager
Set form = page.formConnectform
Set textbox = form.textboxUsername
Call textbox.Drag(89, 12, -244, 6)
Call textbox.SetText("admin")
Call textbox.Keys("[Tab]")
Set table = form.tableYYYYtable
Call table.passwordboxPwd.SetText("XXXX")
table.submitbuttonLogin.ClickButton
page.Wait
Set page = browser.pageXXXConfigurationManagerField
Set textbox = page.tableDbfieldtable.cellColrubrik.textboxShortname
Call textbox.Click(85, 12)
Call page.Keys(" ")
Call textbox.SetText("Mobileno")
delay(5000)
page.buttonSave.ClickButton
page.Wait
End Sub
Could you please suggest me on this.
Thanks and Regards,
Sailaja
Try replacing SetText with Keys. SetText sets the text programmatically and may not trigger some keyboard events that you application may be listening to. Keys simulates actual typing on a keyboard.
To always record tests using Keys, go to Tools > Options > Engines > Recording and change the Record text input... option to Keys.

how to search for all controls on the form in dev express (including sub reports)

I have a dev express report. I want to search for all controls on the report.
The normal convension in windows forms would be:
foreach (Control c in Control.ControlCollection)
{
........
}
Unfortunately this will not work in Dev Express form. Any solutions?
Thanks
There are lots of such questions regarding to find control in report or highlighting cell on mouse over etc..
xrLabel1.Text = ((XRLabel)((XtraReport)xrSubreport1.ReportSource).FindControl("xrLabel1", false)).Text;
subreport control - Check attached sample here
How can set the text of a label on a Subreport?
Check this code snippet to take some idea for your functionality..
Private Sub XtraReport1_BeforePrint(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintEventArgs)
Dim collection As XRControlCollection = (CType(CType(sender, DevExpress.XtraReports.UI.XtraReport),
Q274540.XtraReport1)).Detail.Controls
For i As Integer = 0 To collection.Count - 1
If TypeOf collection(i) Is XRLabel Then
If (CType(collection(i), XRLabel)).DataBindings.Count <> 0 Then
'your code here
End If
End If
Next i
End Sub
XRControl.BeforePrint Event
Report have some structure and you have find control at particular container as you do you in GridView. e.g. find control in editTemplate .. the particular container of the control
Check these links get more information about this:
Loop thru controls of Report or find all visible strings
Find TableCell Controls inside a report
Find all databound controls on report

How to type cast webbrowsercontrolobj.document to mshtml.HTMLDocument VB6? or How to submit form loaded in webbrowser control in vb6?

Hello I am writing code in VB6 only (no VB.NET)
I have webbrowsercontrol object named webbrowser1
I have added reference of microsoft html object library in project.
I am trying this line but is giving error.
Dim doc as MSHTML.HTMLDocument
doc = DirectCast(webbrowser1.document, MSHTML.HTMLDocument)
line 2 is giving error that no method or data found at MSHTML.HTMLDocument
Please help me solving this problem.
What I want is I have one webpage having 2 (html forms) in it. I am loading that page into
webbrowser control by,
webbrowser1.navigate "url"
I have mapped event to handle html button click in webbrowser1's document.
When user clicks on this button I want to submit second form of html page.
Is there any other way to do it?
I also tried following code
'this line is working properly
'this is the code to submit first form in html page
webbrowser1.document.Forms(0).submit
but when I do
'this line is giving error though there are 2 forms available in html page
webbrowser1.document.Forms(1).submit
So ultimate goal is to submit second form of html document.
Please show me right direction.
You need to change Dim doc as MSHTML.HTMLDocument to Dim doc as MSHTML.IHTMLDocument.
Notice the IHTMLDocument has an I at the start, then try to submit the form.
Also, there is no such thing as DirectCast in VB6 - that is only a VB.NET thing.
So just do this:
Dim doc as MSHTML.IHTMLDocument
Set doc = webbrowser1.document
Now you will get intellisense on doc. :)
Let me know how it goes.
Have you tried just direct assignment?
Dim doc as MSHTML.HTMLDocument
Set doc = webbrowser1.document
VB6 doesn't really do casting, but you can access any method (early bound) by assigning it to an variable of the required type, or (late bound) by blindly using a variable of Object type.

Resources