How to Control New Instance of IE

limva
limva used Ask the Experts™
on
I am doing IE automation.  Everything is fine until a new window is created.  How do I take control of this new window exactly like the original window?


Public WithEvents IE As InternetExplorer

Private Sub Form_Load()
   Set IE = New InternetExplorer
   IE.Visible = True
End Sub

Private Sub IE_NewWindow2(ppDisp As Object, Cancel As Boolean)
   Dim WBform1 As Form1
   Set WBform1 = New Form1
   Set WBform1.IE = New InternetExplorer
   Set ppDisp = WBform1.IE
End Sub


Setting ppDisp to WBform1.IE does not seem to work because the new window is not limited by the conditions I placed on its BeforeNavigate2 event.

Any help would be much appreciated.  Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are you using the webbrowser control? Or What project references are you using.

Here is an emxaple of a dynamic copy of IE using a project reference to MS Internet Controls.  I converted this to use in a script which needs user options.

Private Sub Command1_Click()

Dim IE As SHDocVw.InternetExplorer

Dim m$
Set IE = New SHDocVw.InternetExplorer


IE.Visible = True
IE.Navigate2 "About|Blank"


With IE
.ToolBar = True
.StatusBar = False
.FullScreen = True
.Top = 0
.Left = 0
.navigate "about:blank"
.AddressBar = False
'wait till document loaded
Do While IE.readyState <> 4
DoEvents
Loop

End With
   
IE.document.Close

m = "<html><head><title>This is a gas</Title>" + vbCrLf
m = m & "<script type=""text/vbscript"" language=""vbscript"">" + vbCrLf
m = m & "Function Release()" + vbCrLf
m = m & "DIM FRM" + vbCrLf
m = m & "SET FRM=DOCUMENT.FORMS(""fred"")" + vbCrLf
m = m & "FRM(""JIM"").Value=""1""" + vbCrLf
m = m & "End Function" + vbCrLf
m = m & "</SCRIPT>" + vbCrLf
m = m & "</head>" + vbCrLf
m = m & "<Body><form name=""fred"">" + vbCrLf
m = m & "This is an example<br>" + vbCrLf
m = m & "<input type=""hidden"" size=""0"" id=""jim"" value=""0"">" + vbCrLf
m = m & "<input type=""button"" id=""kiss"" value=""Go Now"" onclick='VBScript:release()'>" + vbCrLf
m = m & "</FORM>" + vbCrLf
m = m & "</BODY>" + vbCrLf

IE.document.write m$
IE.Visible = True

Dim frm

Set frm = IE.document.Forms("fred")
Dim dv
Set dv = frm("jim")


Do
    If dv.Value = "1" Then Exit Do
    DoEvents
   
Loop
IE.Quit
Set IE = Nothing



End Sub

Author

Commented:
I am using a reference to MS Internet Controls.  The form that I have is invisible, just to hold my code.

Thanks for your code, inthedark.  However, I don't know how to apply it to my problem.  What I want to do is when a new window is opened from a link (e.g. pop-ups), it does not open using a regular IE but another instance of my program so that the new window is controlled using the same conditions and limitations as the original IE.

Author

Commented:
Can't seem to get any answers!
Hello?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
How do I delete this question?  I don't see a delete button anywhere!
Author of the Year 2009

Commented:
Hi limva,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

limva, Please DO NOT accept THIS comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer

Author

Commented:
Not forgotten.  Just didn't know how to delete a question.
Author of the Year 2009

Commented:
Please see http://www.cityofangels.com/Experts/Closing.htm for help with closing a question.  However, this one will be closed automatically -- and you'll get a refund -- in 7 days, so there is no need to take any action now (just try to keep current on your questions).
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial