my question is to zzzzzooc

Posted on 2004-11-11
Last Modified: 2010-05-02
dear zzzzzooc with refrence to my previous question

everyting is fine. first of all i want to tell u that what i want.
let suppose i open any website. and that website contains frames.
i want to save all the HTMLDocuments from webbrowser and if any HTMLDocument has IFrames then save all IFrames.
upto now i'm able to save all the HTMLDocument within frames and also if First HTMLDocument has one IFrame then it stores as u instructed me.
but it do not work for IFrames of inner HTMLDocuments.
i'm using outer loop for HTMLDocuments and inner loop for IFrames
is this inner loop correct?

If (m_oIE.Document.frames(intLoop).Document.All.tags("IFRAME").length > 0) Then
                For intIFrameLoop = 0 To m_oIE.Document.frames(intLoop).Document.All.tags("IFRAME").length
                    'MsgBox m_oIE.Document.All.tags("IFRAME")(0).contentWindow.Document.body.outerText
                    'MsgBox m_oIE.Document.All.tags("IFRAME")(0).contentWindow.Document.body.outerhtml
                    FILE_TOSAVE_IFRAME = "WebPage" & intLoop & "IFrame" & intIFrameLoop & ".html"
                    Set objIFrameDoc = m_oIE.Document.frames(intLoop).Document
                    Do While objIFrameDoc Is Nothing
                        Set objIFrameDoc = objDoc.All.tags("IFRAME")(intLoop)
                    Open FILES_FOLDER & FILE_TOSAVE_IFRAME For Binary Access Write As #FILE_NUMBER
                    Put #FILE_NUMBER, 1, "<HTML>" + objIFrameDoc.body.outerhtml + "</HTML>"
                    Close #FILE_NUMBER
                    msg = msg & FILES_FOLDER & FILE_TOSAVE_IFRAME & vbCrLf
                Next intIFrameLoop
            End If

hope u understand my problem.
Question by:Naeemg
    LVL 17

    Accepted Solution

    :) Add a reference to "Microsoft HTML Object Library" and try the below. It should recursively search through every frame or iframe. There are security permissions though. The IFrame's SRC must be on the same domain (ie: a site from "" cannot have an iframe that points to ""). It'll raise "Permission Denied". The same may exist for regular frames but I won't test. Just a head's up! Also.. it's not fully tested but it *seems* to work.

    Option Explicit
    Private Sub Command1_Click()
        Call HTMLGet(WebBrowser1.document)
    End Sub
    Private Sub Form_Load()
        'Browse to test-page...
        WebBrowser1.navigate "file://c:\test.html"
    End Sub
    Private Sub HTMLGet(ByRef objDoc As HTMLDocument)
        Dim objCol1 As IHTMLElementCollection, objFrm As HTMLFrameElement
        Dim objCol2 As IHTMLElementCollection, objIFrm As HTMLIFrame
        Call HTMLSave(objDoc.body.outerHTML)
        Set objCol1 = objDoc.All.tags("FRAME")
        For Each objFrm In objCol1
            Call HTMLGet(objFrm.contentWindow.document)
        Next objFrm
        Set objCol2 = objDoc.All.tags("IFRAME")
        For Each objIFrm In objCol2
            Call HTMLGet(objIFrm.contentWindow.document)
        Next objIFrm
    End Sub
    Private Sub HTMLSave(ByVal strHTML As String)
        'change saving routine to whatever.. this is just for testing
        Static lngCnt As Long
        Dim intFF As Integer
        intFF = FreeFile
        Open "c:\TestFile" & lngCnt & ".html" For Binary As intFF
            Put #intFF, 1, strHTML
        Close intFF
        lngCnt = lngCnt + 1
    End Sub
    LVL 5

    Author Comment

    Thank you zzzzzooc

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Mysql vs Oracle 10 104
    VB6 convert MSHFlexgrid1 cells 7 41
    VB 6.0 printer how to align 6 35
    Windows 10 start screen issues 9 39
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now