Get existing IE via VBA
vba ie focus
vba ie readystate
vba select existing internet explorer window
ie document getelementbyid vba
vba check if ie object exists
excel vba get data from internet explorer
enter data in web page using vba
My goal is to scrape data off multiple webpages on the same site into Excel. I have these pages open in tabs within IE8. I have no other IE windows open.
I have tried the following to open IE:
AppActivate "Microsoft Internet Explorer provided by [my company]" ' It loses focus, the titlebar flashes for a fraction of a second ' .. another code .. Dim ShellApp Set ShellApp = CreateObject("Shell.Application") Dim ShellWindows Set ShellWindows = ShellApp.Windows() Dim i For i = 0 To ShellWindows.Count - 1 If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then Set IEObject = ShellWindows.Item(i) End If Next ' Did absolutely nothing, grabbed this code from another solution on stackoverflow
I also tried GetObject (I do not want to use the CreateObject method) as follows
dim ie As InternetExplorer 'also tried As Object and other variation set ie = GetObject(, "InternetExplorer.Application") 'However this is not workable due to security risks and Microsoft ' disabled GetObject for IE by design.
The reason I don't want to use CreateObject or any of the variation is because I already have the tabs open ready to be scraped. AppActivate works with Microsoft Excel, but not IE. I cannot do exact titlebars as follows:
AppActivate "Website name - name page - Microsoft Internet Explorer provided by [my company]"
The reason I can't use this because of the tabs with varying named pages, changing the title constantly. I also tried:
AppActivate InternetExplorer.Application AppActivate InternetExplorer AppActivate " - Microsoft Internet Explorer" AppActivate "Microsoft Internet Explorer"
All of the above either are not recognized or merely flash for a fraction of a second (as mentioned in first code). I have tried other methods but they create a new IE instance when I want to use the existing IE with opened multi-tabs.
In a different code:
AppActivate "[name of page] - Microsoft Internet Explorer provided by [my company]"
worked until I changed it to try and reference IE, no matter what page I'm on. Then the old AppActivate code will no longer work. I broke it. It was dumb of me to not have a back up.
System I am running:
Windows 7, IE8 (I'm waiting on my company to upgrade), Excel 2010
A compressed combination of the above answers, here's what works for me.
(No references required.)
Function GetIE() As Object 'return an object for the open Internet Explorer window, or create new one For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found! Next GetIE If GetIE Is Nothing Then Set GetIE=CreateObject("InternetExplorer.Application") 'Create GetIE.Visible = True 'Make IE window visible End Function
Sub demo() Dim ie As Object Set ie = GetIE 'get new/existing IE object ie.Navigate "http://stackoverflow.com", 2 '2=don't keep history Do: DoEvents: Loop While ie.Busy or ie.ReadyState <> 4'wait til loaded Stop 'do your stuff ie.Quit 'close IE Set ie = Nothing 'clean up End Sub
Get existing IE via VBA - excel - iOS, Get existing IE via VBA - excel. I have tried the following to open IE: AppActivate "Microsoft Internet Explorer provided by [my company]" ' It loses focus, the My goal is to scrape data off multiple webpages on the same site into Excel. I have these pages open in tabs within IE8. I have no other IE windows open. I have tried the following to open IE:
Made some changes and it works now
Function GetIE() As Object Dim ShellApp As Object, ShellWindows As Object Dim IEObject As Object Set ShellApp = CreateObject("Shell.Application") Set ShellWindows = ShellApp.Windows() Dim item As Object On Error GoTo 0 Dim sName As String For Each ObjWind In ShellWindows 'On Error Resume Next If (Not ObjWind Is Nothing) Then sName = ObjWind.Name If sName = "Internet Explorer" Then Set IEObject = ObjWind Exit For 'No need to continue.... End If End If Next If IEObject Is Nothing Then Set IEObject = CreateObject("InternetExplorer.Application") Set ShellApp = Nothing Set GetIE = IEObject End Function
Get existing IE Object - Login Script, In other words, I can't use Shell.Application.Windows for getting an existing instance of IE. Another thing I looked as was GetObject, but whilst Get Title of Internet Explorer; Get URL of Internet Explorer; Create the object of Shell Application Set objShell = CreateObject(“Shell.Application”) Get all the windows using shellobject.Windows. Set objAllWindows = objShell.Windows. Navigate all the windows. For Each ow In objAllWindows. check if window is Internet Explorer. If (InStr(1, ow, “Internet Explorer”, vbTextCompare)) Then
Follow this link to see the code to use an open IE window. http://www.mrexcel.com/forum/excel-questions/553580-visual-basic-applications-macro-already-open-ie-window.html
VBA-Excel: Get ALL The Opened Internet Explorer (IE) using , VBA-Excel: Get ALL The Opened Internet Explorer (IE) using Microsoft Excel. Create the object of Shell Application. Get all the windows using shellobject. Windows. Navigate all the windows. check if window is Internet Explorer. Get HWND property of Internet Explorer. Get Title of Internet Explorer. Get URL of Internet Example below tries to give web automation using IE (internet explorer). VBA macro drives internet explorer using its DOM properties and methods. The macro allows to interact with web page controls (text fields and buttons). The example opens web site www.excely.com and fill a search form to find "excel vba" text.
OK, so I notice a potential problem with the first method you attempt using the Shell object.
You may have an incorrect value for the
.FullName property. (when I debug and examin the
ShellWindows collection, I see path
""C:\Program Files (x86)\Internet Explorer\"
Function GetIE() As Object Dim ShellApp as Object, ShellWindows as Object, i as Long Dim IEObject As Object Set ShellApp = CreateObject("Shell.Application") Set ShellWindows = ShellApp.Windows() For i = 0 To ShellWindows.Count - 1 If InStr(ShellWindows.Item(i).FullName, "C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE") <> 0 Then Set IEObject = ShellWindows.Item(i) Exit For 'No need to continue.... End If Next If IEObject Is Nothing Then Set IEObject = CreateObject("InternetExplorer.Application") Set GetIE = IEObject End Function
You can put this function in your code, just tuck it away somewhere, then whenever you need IE you can call it like:
VBA Macro For Already Open IE Window, Hi all, I'm looking to create a VBA macro which will be ran from Excel (2003 or 2010) & which Count > 0 Then ' Get IE Set IE = shellWins. VBA-Excel: Change Font, Color, Weight of Table Data in the Word document VBA-Excel: Modified Consolidator – Merge or Combine Multiple Excel Files Into One Where Columns Are Not In Order Send Mail With Link to a Workbook, From MS Outlook using Excel.
I figured it out! Thanks to this thread, the following works:
AppActivate " - Microsoft Internet Explorer provided by [my company]" AppActivate " - Microsoft Internet Explorer provided by [my company]"
And it is able to bring forward any site, no matter the naming scheme. Granted, it looks clumsy, but I can't complain if it works.
Using GetObject to reference an Existing Internet Explorer [Resolved , I can create a new instance using CreateObject, or by passing an empty string into the first parameter of GetObject, but I can't seem to get it to I am trying to get an existing (open) IE window to load a new URL via ie.Navigate.. Below is my worksheet code which loads a website on click of a button: Private Sub Sendit_Click() Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True IE.navigate "https://www.yahoo.com" Do Loop Until IE.ReadyState = READYSTATE_COMPLETE GetIE Err_Clear: If Err <> 0 Then Err
VBA - How to activate or select an internet explorer , VBA - How to activate or select an internet explorer browser that is set a reference to Microsoft Internet Controls or you'll get an error about Use the Shell Windows to loop through and keep the first one that you found. Closing remaining IE tabs/windows. Sub testTabClose() Dim oShell As Object Dim oWin As Object Dim IE As Object Dim lTotlWin As Long Dim lCtr Dim lCtr2 Set oShell = CreateObject("Shell.Application") Set oWin = oShell.Windows() lTotlWin = oWin.Count - 1 '/ Starts with zero For lCtr = 0 To lTotlWin If UCase(oWin.Item
How to Show Existing IE Instance if Already Exists , If it is not already open, then start a new instance of IE with that URL. I did find the following code that looks close to what I want, but I get an error msg that library. In VBA, go to the Tools menu, and choose References. In Use this code to get the currently running internet explorer (work atleast with IE9): Dim ie As Object Dim objShell As Object Dim objWindow As Object Dim objItem As Object Set objShell = CreateObject("Shell.Application") Set objWindow = objShell.Windows() For Each objItem In objWindow If LCase(objItem.FullName Like "*iexplore*") Then Set ie = objItem End If Next objItem MsgBox ie.Document.body
GetObject Equivalent for Internet Explorer?, And IE doesn't add itself to the existing applications listing (or whatever it's called) Application Help - Excel Help forum > Excel Programming / VBA / Macros > 'Find an IE window with matching location and get a reference Events in CIM are scripting using VBA. We use Siebel 8 for our CRM software. When a call comes in from CIM and the user takes the call, an event is triggered that does a screen pop in Siebel to pull up the account information. We use thin client for Siebel 8 (Internet Explorer 7 - the company hasn't upgraded to IE8 yet).
- you getting runtime error 5? I can only use the
AppActivatefunction when the specific tab name is the one with focus (Win 7, IE10). It fails otherwise with that error. Have you had a look at the Selenium Wrapper? I have not used it with IE but I have used it briefly with Google Chrome and Firefox, it seems to be a more robust solution and natively supports tabbed browsing. Might be worth spending a few minutes to check it out. code.google.com/p/selenium-vba
- I'm not getting any runtime errors except when I tried doing the GetObject method and gave me the ActiveX error, hence finding out that Microsoft disabled it. As for Selenium Wrapper--it sounds like a dream! //strikeout//I hope it will do what I want it to do. I'll let you know how it goes.\\strikeout\\ Unfortunately, I can't install it due to company restrictions. It will take awhile to get it installed, if I even get the permission to do so. In the meantime, any other workarounds?
- Do you really have "company restrictions" on installing third-party libraries? If so, they are basically saying, "Here is a spoon, go dig the foundation for a skyscraper". What you need is a more powerful tool, if they will not let you have one it is probably a knee-jerk reaction. Lay out the case for it, and seek permission. They'll probably grant it.
- As for other suggestions, no, I have never tried to work with tabbed browser in IE automation, precisely because it either seemed impossible, or not worth the effort when other libraries let me do it easily in other browsers :)
- Thank you David for helping out! I will definitely try to get SW installed. As for tabbed browser, it isn't so much with tabs themselves but the entire browser. I'm using sendkeys to manipulate tabs so that's no problem.
- Verified! Great Job.
- I also tried this method as well. It was actually one of the first places I tried when doing some digging. IE did not register at all, unfortunately. Thank you though.
- I tried the function code, and it gave me the following error: "Invalid procedure call or argument." for the following line:
If InStr(ShellWindows.Item(i).FullName, "C:\Program Files (x86)\Internet Explorer\iexplore.exe") <> 0 Then
- That is perplexing because it is the exact same code that you said you previously used, just a different string comparison. Nothing about that statement should raise an error if it didn't raise an error before.
- It is... I tripled checked to make sure I'm not getting errors in the original script, and I'm not. It just does nothing. I guess I'll create a new object (IE) and then open favorites or older session to open all tabs. Not ideal, but it'll do. Thank you so much David for helping! I am definitely planning on getting the SW IDE. It sounds like the answer I've been searching for. I do a lot of data scraping at work.
- I got it! See answer in this thread, the following works:
- Er, I meant to write that comment into the Answer post for this thread, and to tell you that I figured it out. :)
- This doesn't get the ie object.