title: VBA / Internet Explorer / Javascript: How to open a javascript window from same internet explorer?
body: <p>I am working on intranet. Using <strong>VBA</strong> I have to close some date from a list.</p>
  
  <ul>
  <li>I have selected the dates. Then clicked on a link to close (not button) which triggers a javascript.</li>
  </ul>
  
  <p><strong>Selected all dates:</strong></p>
  
  <p><code>html.getElementsByName("selectall")(0).Click</code></p>
  
  <p><strong>Clicked on the link to close date.</strong></p>
  
  <p><code>html.getElementsByTagName("a")(0).Click
  Do While ie.Busy = True Or ie.readyState &lt;> 4: DoEvents: Loop</code></p>
  
  <p><strong>Part of javascript</strong></p>
  
  <pre><code>{
          //alert(xxx)
          document.first.deletepids.value = xxx
          window.open('closeallocation.asp?hotelid='+hotelid+'&amp;roomtype='+roomtype+'&amp;allocxid='+allocxid,'','toolbar=no,scrollbars=yes,width=500,height=330,top=50,left=80')
          //window.open('closeallocation.asp?deletepids='+xxx+'&amp;hotelid='+hotelid+'&amp;allocxid='+allocxid)
      }
      else
      {
          if(confirm("Room(s) already having bookings for required dates.Do you wish to continue ?"))
          {
              document.first.deletepids.value = xxx
              window.open('closeallocation.asp?hotelid='+hotelid+'&amp;roomtype='+roomtype+'&amp;allocxid='+allocxid,'','toolbar=no,scrollbars=yes,width=500,height=330,top=50,left=80')
          }
          else
              return false;
      }
  </code></pre>
  
  <ul>
  <li>it opens a new window.</li>
  </ul>
  
  <p>How do I either open the javascript window in the same window using VBA or when it opens in a new window  how do get elements or set value or click on the element of the new window?</p>
  
  <p>I have tried to use shell window to search for all the opened window with title and locationurl but I didnt find that particular window for some reason.</p>
  
  <pre><code>Dim ow As ShellWindows
  Dim fw As Variant
  Dim html As HTMLDocument
  Dim ie As InternetExplorer
  
  Set ie = New InternetExplorer
  Set ow = New ShellWindows
  
      For Each fw In CreateObject("Shell.application").Windows
  
          'On Error GoTo ErrorMsg
          If fw = "Internet Explorer" Then
              If InStr(fw.LocationURL, "displayhotelallocsummary.asp") &lt;&gt; 0 Then
              Exit For
              End If
          End If
      Next fw
  
  Set ie = fw
  Set html = ie.document
  </code></pre>
  
  <p>Please advise.</p>