+ Reply to Thread
Results 1 to 13 of 13

Need help using VBA to interact with a Child Window in IE8

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Need help using VBA to interact with a Child Window in IE8

    Hello,

    I am having trouble getting my code to interact with a Child Window in Internet Explorer. On our intranet webpage, when you click on a link, a RadWindow pops up. A RadWindow is a Modal Popup window, which is a Child Window of a Parent. The code I usually use does not work because it is only looking at the Parent Windows:

    Please Login or Register  to view this content.
    Does anyone know how to modify the code to look for a Child Window using VBA?

    Thanks,
    Matt

  2. #2
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help using VBA to interact with a Child Window in IE8

    Here is an example of the problem I have. The attached spreadsheet has a button that when clicked will open a website that has an example of a RadWindow, which is a window within a window. It will read the value of an element on the parent window, which in this case is "POST", and display it in a message box. Then it will attempt to read and display the value of an element from the RadWindow (Child Window), and this is where I get an error. I can't figure out how to access the Child Window rather than the Parent.

    Here is the code, if you would rather create a new workbook from scratch:

    Please Login or Register  to view this content.
    Thanks,
    Matt
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help using VBA to interact with a Child Window in IE8

    ***Bump***

  4. #4
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help using VBA to interact with a Child Window in IE8

    ***Bump***

  5. #5
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need help using VBA to interact with a Child Window in IE8

    Your example workbook attempts to interact with the RadWindow in http://demos.telerik.com/aspnet-ajax...defaultcs.aspx, but that child window is inside an iframe which VBA can't access.

    Do you mean this modal pop-up window? http://demos.telerik.com/aspnet-ajax...defaultcs.aspx

    In which case:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

  6. #6
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help using VBA to interact with a Child Window in IE8

    Thanks for the response. The window I am trying to access is similar to the one found on the website I provided: http://demos.telerik.com/aspnet-ajax...defaultcs.aspx

    Since it is in an iframe, there is no way for VBA to access it?

    Some forum posts I have been looking at with similar Parent/Child window problems suggest using WithEvents and NewWindow2 to locate the child window:

    http://www.mrexcel.com/forum/excel-q...ld-window.html

    http://visualbasic.about.com/od/stan...ieinstance.htm

    However I have not been able to get it to work. This is my first time trying to access a child window.

    Thanks,
    Matt

  7. #7
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need help using VBA to interact with a Child Window in IE8

    That MrExcel thread is for IE browser windows. Your child window seems to be a dynamic HTML/Javascript/AJAX window and is completely different. If you look at the source, the child window is inside an < IFRAME > element, and this iframe contains a HTMLDocument, but I don't know how to access this document.

  8. #8
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Need help using VBA to interact with a Child Window in IE8

    Ah, thats why no matter what I tried I couldn't get it to work. Unfortunately I haven't much luck finding out how to use VBA to access a RadWindow, this WithEvents/NewWindow2 method is the closest I've been.

  9. #9
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need help using VBA to interact with a Child Window in IE8

    This code shows how to access the HTMLDocument inside the iframe - the child window within http://demos.telerik.com/aspnet-ajax...defaultcs.aspx.

    If the iframe document is on the same domain or sub-domain as the parent document then we can access it directly using iframe.contentDocument, or iframe.contentWindow.document.

    However, if the iframe document is on a different domain or sub-domain then we can't access it directly due to cross-site scripting restrictions (the VBA error is "Permission denied") and instead we must navigate to the iframe's src URL.

    This code attempts the first method and if that fails uses the second method. For http://demos.telerik.com/aspnet-ajax...defaultcs.aspx, the child window is on a different sub-domain (www.telerik.com) to the parent document (demos.telerik.com) so the cross-site scripting restriction is imposed and IE is navigated to www.telerik.com to get the child window. This navigation could be done in another, hidden IE window.
    Please Login or Register  to view this content.
    You should be able to apply the same technique to your intranet page.

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Need help using VBA to interact with a Child Window in IE8

    Wouldn't it just be easier to navigate to the frame source in the first instance?

  11. #11
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need help using VBA to interact with a Child Window in IE8

    Yes, but only if you know the URL and it doesn't change, e.g. it could have a session id or be a Javascript link.

    In this case, I took the OP's request as programmatically navigating to the parent document and then interacting with the embedded child document without hard-coding and navigating directly to the child's URL. But without knowing the exact HTML it's difficult to say whether my code above works for his situation.

  12. #12
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Need help using VBA to interact with a Child Window in IE8

    True, however one should be able to parse the location of the iframe from the source code upon inspection - even if generated from JavaScript, it would be considerably lighter than automating IE. RE: the session, there's no particular reason you need to use IE to authenticate and use a session.

    I wasn't commenting on your code more on the initial requirement

  13. #13
    Registered User
    Join Date
    05-09-2019
    Location
    Spain
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Need help using VBA to interact with a Child Window in IE8

    Hi all. I'm new to the forum. I know this is a quite old post, but just made my day. Thanks!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to assign an object to a child IE window
    By Jason in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-27-2014, 10:01 AM
  2. Controlling Child Window in IE
    By rlee12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-28-2013, 09:33 PM
  3. VBA / Web Automation / Finding child IE Window:
    By downtown1933 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2013, 01:58 PM
  4. Replies: 6
    Last Post: 12-03-2012, 05:41 PM
  5. Replies: 3
    Last Post: 07-09-2010, 02:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1