VBA - IE sessions on dual monitors

mtharnden

Board Regular
Joined
Aug 17, 2011
Messages
114
hello, simply put, i want VBA to open two seperate sessions of IE on two seperate displays.

i have not been able get the display part to work and not finding anything so i am not sure if i need seperate sessions but would like to do so to be safe (doing it manyally on the computers using i have to have seperate sessions of IE to do full screen on the two monitors).

current code: (this opens two IE windows on full screen on the default monitor)

Code:
Sub Test()

Dim objIE As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Fullscreen = 1
objIE.navigate "http://www.google.com"

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Fullscreen = 1
objIE.navigate "http://www.yahoo.com"

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try This

Code:
Sub Test()


Dim objIE1 As Object, objIE2 As Object


Set objIE1 = CreateObject("InternetExplorer.Application")
objIE1.Visible = True
objIE1.Left = 0
objIE1.Fullscreen = 1
objIE1.navigate "http://www.google.com"


Set objIE2 = CreateObject("InternetExplorer.Application")
objIE2.Visible = True
objIE2.Left = objIE1.Left + objIE1.Width + 1
objIE2.Fullscreen = 1
objIE2.navigate "http://www.yahoo.com"


End Sub

FYI: There's really nice (adaptable VB) routines here to enum monitors.
 
Upvote 0
Try This

Code:
Sub Test()


Dim objIE1 As Object, objIE2 As Object


Set objIE1 = CreateObject("InternetExplorer.Application")
objIE1.Visible = True
objIE1.Left = 0
objIE1.Fullscreen = 1
objIE1.navigate "http://www.google.com"


Set objIE2 = CreateObject("InternetExplorer.Application")
objIE2.Visible = True
objIE2.Left = objIE1.Left + objIE1.Width + 1
objIE2.Fullscreen = 1
objIE2.navigate "http://www.yahoo.com"


End Sub

FYI: There's really nice (adaptable VB) routines here to enum monitors.

thanks! that is what i needed! i was playing with the .left just didnt get it correct.

i wont be able to test if this route has any issues with different sessions as the computer i am on now doesnt have that issue but ill see next week how
 
Upvote 0
wait...
it worked with those web pages however when i changed to a local HTML file i get an error...
the first window will open just fine, then 2nd errors at
objIE2.Left = objIE1.Left + objIE1.Width + 1

error message:
Run-time error "-2147023179 (800706b5)':
Automation error
The interface is unknown
 
Upvote 0
Identical code as posted above?

yes, only exception was the URL.

works with google/yahoo but when i change to the local HTML file it opened the first fine but not the 2nd.

would crash here so IE window opened, on correct window, but never goes on to fullscreen or navigate:
objIE2.Left = objIE1.Left + objIE1.Width + 1

the navigate looks something like this (edited for security purposes)
objIE2.navigate "\\something\shared\folder\file.htm"


i tried using google on objIE1 and an HTML file on objIE2 and that worked just fine. THIS should help identify the issue.
 
Upvote 0
Update*
i looked at the locals and noticed the values resetting to nothing on objIE1 when it moved on to objIE2

i added two variables to get the left and width before it loses it and it now works.

thank you for the help!
 
Upvote 0
I understand you have the work-around, however it's bothersome to me that objIE1 would report as Nothing until the code set it as such or the user killed it.

It's my contemplation that the .Fullscreen & .navigate directives would
#1) Re-draw the window
#2) start the page loading process
#3) fire off a bunch of it's own events in IE

All of which consume processing cycles.
In creating objIE2, we referenced objIE1 before it was completely done firing its events and drawing it's window.

We can, however, pause until such time objIE1 is ready.
Code:
Do
    DoEvents
Loop While objIE1.ReadyState <> READYSTATE_COMPLETE

Just couldn't quite leave this as it was.
 
Upvote 0
I understand you have the work-around, however it's bothersome to me that objIE1 would report as Nothing until the code set it as such or the user killed it.

It's my contemplation that the .Fullscreen & .navigate directives would
#1) Re-draw the window
#2) start the page loading process
#3) fire off a bunch of it's own events in IE

All of which consume processing cycles.
In creating objIE2, we referenced objIE1 before it was completely done firing its events and drawing it's window.

We can, however, pause until such time objIE1 is ready.
Code:
Do
    DoEvents
Loop While objIE1.ReadyState <> READYSTATE_COMPLETE

Just couldn't quite leave this as it was.


Bot it sure how the readystate works, I haven't used it before.


I'll look at that and see also exactly when locals shows it losing it's values. While my workaround worked I do want to do this the best way, I'm trying to better my vba skills .
 
Upvote 0
OK, when i reach the below line all expressions of objIE1 show the value as <automation error="">
Set objIE2 = CreateObject("InternetExplorer.Application")

when it moves to the next line it shows objIE1 as no varriables
objIE2.Visible = True

*when i say on that line, when using debugger (F8) is highlighting that line so i guess it would be the line prior actually? if so it is the .navigat giving the automation error and set objIE2 setting it as no variables


lastly two more questions --
since i am using this to have it where when these computers reset all i have to do is log in and walk away (the macro is st to run on open and the file in the startup folder), the computer opens a couple other things on startup so i put a 30 seconds wait which gives it enough time for those to startup to try and get the IE windows on top however office communicator</automation> sometimes (about 50% of the time) will move to the front after the macro runs. i cannot get a line of code working for some reason to exit communicator. Using what is below i found on google, but i have not used VBA to work communicator in a while so drawing blanks.

Code:
Dim msgr As CommunicatorAPI.IMessengerConversationWndAdvanced
msgr.close

after it finishes, windows taskbar pops up since it sees new active windows (IE icon blinks orange), is there a way to not have that happen easily? i have taskbar set to autohide so if i click anywhere it will go away but trying to avoid having to touch anything.
 
Upvote 0

Forum statistics

Threads
1,220,933
Messages
6,156,937
Members
451,386
Latest member
leolagoon94

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