Search code examples
excelvbamshtml

Can I write an InternetExplorer.document to another InternetExplorer window?


I'd like to bring the IE.Document of one window into the IE.document of another window. Can this be done?


Solution

  • I can't see the sense behind your question. But you can do that in this way:

    Sub DocFromIEtoIE()
    
    Dim ieOne As Object
    Dim ieTwo As Object
    Dim nodeHTML As Object
    Dim htmlDoc As String
    Dim url As String
    
      url = "https://stackoverflow.com/"
    
      Set ieOne = CreateObject("internetexplorer.application")
      ieOne.Visible = True
      ieOne.navigate url
      Do Until ieOne.ReadyState = 4: DoEvents: Loop
    
      Set nodeHTML = ieOne.document.getElementsByTagName("html")(0)
      If Not nodeHTML Is Nothing Then
        htmlDoc = nodeHTML.outerHTML
    
        Set ieTwo = CreateObject("internetexplorer.application")
        ieTwo.Visible = True
        ieTwo.navigate "about:blank"
        Do Until ieTwo.ReadyState = 4: DoEvents: Loop
    
        ieTwo.document.Write (htmlDoc)
      End If
    End Sub