Internet Explorer Automation - New Tab

powershot32

New Member
Joined
Aug 26, 2014
Messages
18
I have a macro that will grab information from a excel document, open a webpage, navigate a html form and open a new tab from the HTML field related to the excel document. This is where I get stuck.

I'm trying to paste the copied information from the document onto this page but I can't seem to get it to work.

Here is my code that works on the initial website

Set SearchButton = IE.Document.getElementsByName("body:productSearchForm:searchButton")
For Each Butt******* In SearchButton
If Butt*******.Value = "S(e)arch" Then
Butt*******.Click
Exit For
End If
Next Butt*******

So that correctly clicks the search button after it has entered the data into the search field. However once the new tab opens and I have to click another button it doesn't work. I use the same exact code (obviously formatted to find the correct button) but the button never gets clicked and I don't even get an error. The macro just ends doing nothing.

Here is the code after the search.

application.Wait (Now + TimeValue("00:00:05"))

Set ShowAll = IE.Document.getElementsByName("body:attributesForm:showAll")
For Each AllClick In ShowAll
If AllClick.Value = "Show (A)ll" Then
AllClick.Click
Exit For
End If
Next AllClick

So I ruled out the wait time, because I've gone up to 10 seconds and it still just ends, so its not that the website is taking too long to load. Does it have something with the new tab being opened and the macro still trying to run on the other webpage and not the new tab? Or is there something else I am missing?

Thanks for any help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
So I just figured out that the macro still treats the original website as the focus. Does anyone know how to switch the focus over to the newly opened tab? Internet Explorer already switches over the active window to the new tab but the macro still is lingering on the first page. I've looked around online and can't find any solution that works since the URL will be unique to each different excel document I need to copy info from.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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