[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


my question is to zzzzzooc

Posted on 2004-11-11
Medium Priority
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

zzzzzooc earned 500 total points
ID: 12553106
:) 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 "a.com" cannot have an iframe that points to "b.com"). 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

Author Comment

ID: 12678967
Thank you zzzzzooc

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 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