how to save multiple web page content by ie control

alap43841

Registered User.
Local time
Today, 14:58
Joined
May 9, 2006
Messages
36
I have a database where I save web page contents in txt file as delimited file which again used in the database as linked table. I am not a VBA expert, I searched around the net and got those codes to execute my requirements. I need to save more than one page during the form loading. The procedure I am presently using is as follows:

Code:
[COLOR="Red"]
'This Part of the code is working with form load property[/COLOR]
Private Sub Form_Load()
Dim colTables As Object
      Dim strDocHTML As String
      Set ieBrowser = CreateObject("internetexplorer.application")
   [COLOR="Red"] 'URL of the webpage[/COLOR]
    ieBrowser.Navigate "http://web.dse.com.bd/admin-real/latest_share_price_all.php"
        While ieBrowser.Busy 'WAIT LIKE USUAL
    DoEvents
    Wend
      
      While ieBrowser.Document.All.tags("TABLE").Length > 1
         DoEvents
      Wend
    
Set colTables = ieBrowser.Document.All.tags("TABLE")
[COLOR="Red"]'creating bar delimited text file[/COLOR]
CreateBarDelimitedFile colTables(0).innerHTML
Set colTables = Nothing
Set ieBrowser = Nothing
end sub



[COLOR="Red"]'this is for creating the text file[/COLOR]
Sub CreateBarDelimitedFile(HTMLTable As String)
Dim blnCapture As Boolean, blnInTag As Boolean
Dim lngItem As Long
Dim intFile As Integer, intNestledTable As Integer
Dim strHTML As String, strOutput As String
intFile = FreeFile
'the path where the text file will be saved
Open CurrentProject.Path & "\IntraDayXL.txt" For Output As #intFile
'cycle trough the contents one character at a time
For lngItem = 1 To Len(HTMLTable)
  'Starting a tag so ingore the character until text ends
  If Mid(HTMLTable, lngItem, 1) = "<" Then
    blnInTag = True
  End If
  
  'They nestled a table in the one we want, keep track to know
  'when the current row ends
  If Mid(HTMLTable, lngItem, 6) = "<TABLE" Then
    intNestledTable = intNestledTable + 1
    lngItem = lngItem + 6
  End If

  'Current character is not in a tag so check to see if it
  'should be captured
  If Not blnInTag Then
    'Test to see if the current character begins a special character
    If Mid(HTMLTable, lngItem, 1) = "&" Then
      'Most* HTML special characters start with '&' and end ';' so
      'skip over them
      Do
        lngItem = lngItem + 1
      Loop Until Mid(HTMLTable, lngItem, 1) = ";"
    Else
      'it dosen't so capture the character
      strOutput = strOutput & Mid(HTMLTable, lngItem, 1)
    End If
  End If
  
  'we are at the end of a row so put in a delimiting character '|'
  If Mid(HTMLTable, lngItem, 3) = "<TD" Then
    strOutput = strOutput & "|"
    lngItem = lngItem + 3
  End If
  
  'Cycled through all the nestled tables and the row delimiter
  'has been reached so write to the output file
  If Mid(HTMLTable, lngItem, 3) = "<TR" And intNestledTable = 0 Then
    'to keep the output on the same line remove the line feeds
    strOutput = Replace(strOutput, vbCrLf, "")
    'Make sure there is data to write
    If Len(strOutput) <> 0 Then
      Print #intFile, strOutput
    End If
    'clear the output in preperation for the next line
    strOutput = ""
    lngItem = lngItem + 3
  End If
  
  'update the nested table pointer
  If Mid(HTMLTable, lngItem, 8) = "</TABLE>" Then
    intNestledTable = intNestledTable - 1
    lngItem = lngItem + 8
  End If
  
  'Probably reached the end of the tag
  If Mid(HTMLTable, lngItem, 1) = ">" Then
    blnInTag = False
  End If
Next lngItem
Close #intFile
End Sub


Here I need to save more web pages with form load event of the same form and save those content as bar delimited text file. To be more precise I need to save content of four webpage as a delimited text file when I load a form.

I have no knowledge on VBA, please suggest a solution considering my limited knowledge..............thanks
 

Users who are viewing this thread

Back
Top Bottom