VBA & Tabbed Browsing

Sthrncali

Board Regular
Joined
Apr 1, 2011
Messages
226
Good Morning...

Curious if anyone has some experience working with Tabbed Browsing in VBA... I currently have a routine that opens multiple webpages and pulls data into a spreadsheet from those pages. However, I recently came accross some code that will open up the different pages in tabs, as opposed to opening multiple windows at once, and I was trying to modify my code to do the same.


I have gotten it to open my pages successfully in tabs, however the problem I am running into is how to assign each tab to a variable. My original code opened 4 webpages at the same time, and they were identified as such:

Code:
Dim IE(4) as Variant
 
For Var = 1 to 4
Set IE(Var) = IEWindow.Navigate HLink
Next
Then the code waited for all 4 pages to load, then it would cycle through all four and pull down HTML code:

Code:
For Var = 1 To 4
y = IE(Var).Document.body.innerHTML
'Do something with y
Next

What I have done so far is moved this line out of my loop:

Code:
Set IEWindow = CreateObject("INTERNETEXPLORER.APPLICATION")

But then I tried to do


Code:
Set IE(Var) = IEWindow.Navigate HLink, 2048

and I get a syntax error. Is there a way to set a tabbed .navigate to a variable so I can refer to it later in the routine?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Why do you want to open them in the same instance of IE?

Can't you get the data from the separate instances?
 
Upvote 0
I was thinking it may be more efficient systematically to open them in tabbed then seperate instances of IE.

The code actually rolls through about 130 different webpages 6 at time... So currently I open 6 different IE Windows, Navigate to 6 Pages, Wait for them to load, scrub HTML, then close all IE browsers, then cycle through the next 6 links.

Would it not take up less system resources to use 1 instance, 6 tabs, as opposed to 6 instances?
 
Upvote 0
I don't know to be sure but if there was a difference then it might not be significant.

There might be other factors as well - connection speeds, traffic etc.

Why are you opening 6 pages at a time anyway?

Are they connected and you need all 6 open at the same time for whatever it is you are doing?

For example. perhaps you need to cross-reference from one page to another?
 
Upvote 0
I open 6 at a time because of the source server. Its actually an internal webserver that we query for performance data. The nature of the server is I can load 1 page or 6 pages just a fast... Meaning if it takes 30 seconds for a query to run, and i do them in parallel, I get all 6 queries finished in 30 seconds. The server processes all of them at the same time. Alternatively if I loaded them one at a time, it would take each 30 seconds to run so 30 x 6 = 180 seconds of page loading time.

The wait time is not a product of network traffic, but rather server processing time. So running them in parallel exponentially increases the overall time it takes to download all 130 reports.

If my desktop could support it, I would load 10 at a time but it eats up my local system resources - that's why I wanted to test and see if tabbed browsing would use up less local resources.
 
Upvote 0
Sorry

I've searched on this topic before, and today but can't find anything.

I'm sure it can be done but perhaps not do many people have worked on it, so there's nothing to find.

Or I'm looking in the wrong place(s).)

PS Did find some JavaScript stuff but it didn't work for when I tried it as script or when I 'converted' it to VBA.
 
Upvote 0
So Sthrncali, did you find a way to navigate between tabs? I recently need to do a project alike this but couldn't find anything. Thought you probably have an answer since this thread was posted a year ago. If you don't mind, please share your findings if you made it to work. Thank you so much.

Ian
 
Upvote 0
Well, yes and no! :)

I wasn't able to locate/develop any script that was able to navigate tabbed pages directly, but the workaround I used for my purposes (ability to load several pages at once, without loading down local system resources), was to process them without "drawing" the IE windows.

Meaning, setting the property IE.Visible = False, allowed me to process 20x windows at a time, without a noticeable resource drain on my local system.

I accomplished this by creating an Object Array of IE browser's, and looping through them.

Example:

Code:
Public IE(20) As Object
Public Dest(20) As String
Public CounterMax As Integer

CounterMax = 0


Do
'ASSIGN ARRAY POSITION USING IE(Counter)
        CounterMax = CounterMax + 1
        Set IE(CounterMax) = CreateObject("INTERNETEXPLORER.APPLICATION")
        Application.Wait 2
        With IE(CounterMax)
            .Visible = False
            .Navigate BookLink
        End With
Loop

'Loop Until All IE Windows Loaded, using whatever logic necessary
'Now you can refer to each individual IE window as IE(x), and process it according.

Example:
------------------------
For i = 1 to CounterMax
IE(i).Quit
Next i
------------------------
'End Example
 
Upvote 0
Interesting point. I will give it a shot and see if this works.

BTW, I have code from Norie to open in a separate window instead of a tab. Please let me know if you want to try that.

Thanks,

Ian
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

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