I recently submitted some code for CreateObject("InternetExplorer.Application") to interact with a site. It is fairly slow though do to the fact that the pages have to load before processing.
The code is fairly short & working ... Insert some text into a textbox on the first page of the website, click a button on the website page to process the inserted text, & then download a file that is generated from the next page that is loaded.
I have previously converted for grabbing data from a website, but I have no idea how, or if it is even possible to do 'clicks'/download with, for example, MSXML.
Any help?
The code is fairly short & working ... Insert some text into a textbox on the first page of the website, click a button on the website page to process the inserted text, & then download a file that is generated from the next page that is loaded.
VBA Code:
Sub IE_Browser_Test()
'
Dim Browser As Object
Dim CopiedData As String, WebSite As String
Dim WB As Workbook
'
WebSite = "https://my.gstzen.in/p/gstin-validator/" ' <--- Set this to the website that you want to go to
'
Sheets("Sheet1").Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy ' Copy data from sheet to clipboard
CopiedData = CreateObject("htmlfile").parentWindow.clipboardData.GetData("Text") ' Save contents from clipboard into CopiedData
'
Set Browser = CreateObject("InternetExplorer.Application")
'
With Browser
.Visible = True ' Set IE window status to visible
.Navigate WebSite ' Go to the website
'
Do While .Busy Or .ReadyState <> 4 ' Loop to wait for website to fully load
DoEvents
Loop ' Loop back
'
.Document.getElementsByTagName("textarea")(0).innerText = CopiedData ' Copy data to text box on website
.Document.querySelector("button[type=submit]").Click ' Click the 'Check GSTIN/UIN Numbers' button
'
Do While .Busy Or .ReadyState <> 4 ' Loop to wait for website to fully load
DoEvents
Loop ' Loop back
'
Set WB = Workbooks.Open(.Document.querySelector("[class='pull-right btn btn-sm btn-excel']")) ' Open the download link into Excel workbook
'
.Quit ' Close the browser
Set Browser = Nothing ' Clear browser from memory
End With
End Sub
Book2 | ||||
---|---|---|---|---|
A | B | |||
1 | 09ABIPM5346A1ZS | |||
2 | 06AAVPK7054P1ZT | |||
3 | 29AAACD1390F1ZU | |||
4 | 27AAFCK1511N1ZI | |||
5 | 27AAFCK1511N1ZI | |||
6 | 06AXFPA2657R1Z5 | |||
7 | 06AXFPA2657R1Z5 | |||
8 | 29AAACP0165G1ZL | |||
9 | 29AAGCR3967G1ZX | |||
10 | 29AALCR3173P1ZJ | |||
11 | 29AIUPB4936C1Z4 | |||
12 | 29AIUPB4936C1Z4 | |||
13 | 29ADDFS6267R1Z1 | |||
14 | 33AAKCS6703M1Z2 | |||
15 | 27AEWPJ1063J1Z4 | |||
16 | 29AAACS9735K1ZR | |||
17 | 29AHXPT9340A1ZQ | |||
18 | 09AAGFU9919G1ZM | |||
19 | 33AAMFV5931D1Z6 | |||
20 | 27DREPK9227D1ZQ | |||
21 | 06AABCV3609C1ZR | |||
22 | 09AABCV3609C1ZL | |||
23 | 09AABCV3609C1ZL | |||
24 | 06AABCV3609C1ZR | |||
25 | 06AABCV3609C1ZR | |||
26 | 09AABCV3609C1ZL | |||
27 | ||||
Sheet1 |
I have previously converted for grabbing data from a website, but I have no idea how, or if it is even possible to do 'clicks'/download with, for example, MSXML.
Any help?
Last edited: