How do I select an already open IE window and save its web page source code to local *.txt file?

RX180

New Member
Joined
Jul 29, 2014
Messages
1
I need to grab some public data from a website, but the data in question is only accessible if the user clicks in an link that opens a new IE window with the desired data. Despite being newbie to Excel / VBA I managed to do a rudimentary code able to click on the link that opens the window with the desired data. Here is my code:


Code:
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)

Sub NavigateClick()

Dim Browser As Object
Dim URL As String
Dim nTabs As Integer

Set Browser = CreateObject("InternetExplorer.Application")
URL = "this *.asp webpage contains the link to be clicked"

Browser.Navigate (URL)
Browser.Visible = True

Do
Loop Until Browser.ReadyState = READYSTATE_COMPLETE 'Waits for the load of the web page containing the link to be clicked
Sleep 1000

For nTabs = 0 To 25 'For loop to select the link
SendKeys "{TAB}"
Sleep 50
Next nTabs

SendKeys "{ENTER}" 'click on the link

Do
Loop Until Browser.ReadyState = READYSTATE_COMPLETE
Application.Wait DateAdd("s", 2, Now)   'Wait for new IE window that contains the source code to be saved to local file

Browser.Quit 'Close the first IE window

Set Browser = Nothing 'Frees memory

End Sub

So far everything is working fine.

Now I need a code to select the new opened window and save the source code of it's webpage to a local *.txt file. I have tried some examples, including queries to the first page that shows the desired data too, but none worked. The only way I found to grab the data was saving the source code of the second web page to disk and parsing it. :eek:

Can someone help me?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,215,660
Messages
6,126,089
Members
449,288
Latest member
DjentChicken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top