Internet Explorer Object

Posted on 2004-09-14
Last Modified: 2012-06-22
I'm making a dll file and i used IE object in that class.
i want to save some data to file on disk.
I used RichText box object to save data to file, but it doesnot work  in this class.
can anyone help?
Question by:Naeemg
  • 2
LVL 16

Expert Comment

ID: 12054199
What do yo mean by "but it doesnot work  in this class."??
LVL 14

Expert Comment

ID: 12058018
Whatever you are trying to do, you don't need to use the RichText box to save data from IE.
Post the code you have so far so we can apply the corrections.

Author Comment

ID: 12061674
ok following is the source code of my DLL. In the last function saveIEHTMLData() i want to save html data to file on disk.
in that function i'm only able to display that html data into message box, but i want that data to be stored in a file on desired location. thanks

Option Explicit

' ····----==== Interfaces ====----····

Implements IObjectWithSite
Implements olelib2.IOleCommandTarget

' ····----==== Private Fields ====----····

Private m_oSite As IUnknown
Private m_oIE As InternetExplorer

' ····----==== APIs ====----····

   dwStructSize As Long
   lpszSourceUrlName As Long
   lpszLocalFileName As Long
   CacheEntryType  As Long
   dwUseCount As Long
   dwHitRate As Long
   dwSizeLow As Long
   dwSizeHigh As Long
   LastModifiedTime As Currency
   ExpireTime As Currency
   LastAccessTime As Currency
   LastSyncTime As Currency
   lpHeaderInfo As Long
   dwHeaderInfoSize As Long
   lpszFileExtension As Long
   dwExemptDelta  As Long
   Buffer(0 To 1023) As Byte
End Type


Private Declare Function FindFirstUrlCacheEntry Lib "wininet" _
   Alias "FindFirstUrlCacheEntryA" ( _
   ByVal lpszUrlSearchPattern As String, _
   lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
   lpdwFirstCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindNextUrlCacheEntry Lib "wininet" _
   Alias "FindNextUrlCacheEntryA" ( _
   ByVal hEnumHandle As Long, _
   lpNextCacheEntryInfo As Any, _
   lpdwNextCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindCloseUrlCache Lib "wininet" ( _
   ByVal hEnumHandle As Long) As Long

Private Declare Function DeleteUrlCacheEntry Lib "wininet" _
   Alias "DeleteUrlCacheEntryA" ( _
   ByVal lpszUrlName As String) As Long

Private Declare Function lstrcpyA Lib "kernel32" ( _
  ByVal RetVal As String, _
  ByVal Ptr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" ( _
  ByVal Ptr As Any) As Long

' ····----==== IObjectWithSite Methods ====----····

Private Sub IObjectWithSite_GetSite(riid As olelib.UUID, ppvSite As stdole.IUnknown)
Dim oUnk As olelib.IUnknown

   ' Get the IUnknown interface
   Set oUnk = m_oSite
   ' Query for the interface
   oUnk.QueryInterface riid, ppvSite
End Sub

Private Sub IObjectWithSite_SetSite(ByVal pUnkSite As stdole.IUnknown)
   ' Store the site
   Set m_oSite = pUnkSite
   If pUnkSite Is Nothing Then
      Set m_oIE = Nothing
      ' Get the InternetExplorer object
      Set m_oIE = GetIE(pUnkSite)
   End If
End Sub

' ····----==== IOleCommandTarget methods ====----····

Private Sub IOleCommandTarget_Exec(pguidCmdGroup As olelib.UUID, ByVal nCmdID As Long, ByVal nCmdexecopt As olelib.OLECMDEXECOPT, pvaIn As Variant, pvaOut As Variant)

   ' Clean the temporary folder
End Sub

Private Sub IOleCommandTarget_QueryStatus(pguidCmdGroup As olelib.UUID, ByVal cCmds As Long, prgCmds As olelib.OLECMD, pCmdText As olelib.OLECMDTEXT)

   ' Always enabled
   prgCmds.cmdf = OLECMDF_ENABLED
End Sub

' ····----==== Other methods ====----····

Private Function GetIE( _
   ByVal ServiceProvider As olelib.IServiceProvider) As IWebBrowserApp
Dim IID_IWebBrowserApp As olelib.UUID
   CLSIDFromString IIDSTR_IWebBrowserApp, IID_IWebBrowserApp
   ServiceProvider.QueryService IID_IWebBrowserApp, _
                                IID_IWebBrowserApp, _
End Function

Private Sub CleanTemporaryFolder()
Dim lHandle As Long
Dim sURL As String

   tEI.dwStructSize = Len(tEI)

   lHandle = FindFirstUrlCacheEntry(vbNullString, tEI, Len(tEI))
   If lHandle <> 0 Then
         If (tEI.CacheEntryType And NORMAL_CACHE_ENTRY) <> 0 Then
            sURL = StringFromPointer(tEI.lpszSourceUrlName)
            m_oIE.StatusText = "Deleting " & sURL
            MsgBox ""
            'DeleteUrlCacheEntry sURL
         End If
      Loop While FindNextUrlCacheEntry(lHandle, tEI, Len(tEI))
      FindCloseUrlCache lHandle
   End If
   m_oIE.StatusText = "Done"
End Sub

Private Function StringFromPointer(ByVal Ptr As Long) As String

   StringFromPointer = Space$(lstrlenA(Ptr))
   lstrcpyA StringFromPointer, Ptr
End Function

Sub saveIEHTMLData()
    m_oIE.StatusText = "My Button is pressed."
    MsgBox "m_oIE.Document.body.outerHTML" & m_oIE.Document.body.outerHTML
    MsgBox "m_oIE.Document" & m_oIE.Document
    'MsgBox "m_oIE.LocationName" & m_oIE.LocationName
    'MsgBox "m_oIE.LocationURL" & m_oIE.LocationURL
    'MsgBox "m_oIE.Name" & m_oIE.Name
    'MsgBox "m_oIE.Path" & m_oIE.Path
    'MsgBox "m_oIE.hWnd" & m_oIE.hWnd
End Sub
LVL 14

Accepted Solution

aelatik earned 125 total points
ID: 12062920
Sub saveIEHTMLData()
    m_oIE.StatusText = "My Button is pressed."
    MsgBox "m_oIE.Document.body.outerHTML" & m_oIE.Document.body.outerHTML
    MsgBox "m_oIE.Document" & m_oIE.Document
    'MsgBox "m_oIE.LocationName" & m_oIE.LocationName
    'MsgBox "m_oIE.LocationURL" & m_oIE.LocationURL
    'MsgBox "m_oIE.Name" & m_oIE.Name
    'MsgBox "m_oIE.Path" & m_oIE.Path
    'MsgBox "m_oIE.hWnd" & m_oIE.hWnd

    Dim FILE_TOSAVE As String
        FILE_TOSAVE = "c:\yourfilename.txt"
    Dim FILE_NUMBER As Integer ' Declare variable
        FILE_NUMBER = FreeFile ' Assign a free resource
        Open FILE_TOSAVE For Binary Access Read Write As #FILE_NUMBER
            Put #FILE_NUMBER, 1, m_oIE.Document.body.outerHTML
        Close #FILE_NUMBER  
    msgbox "File is saved to " & FILE_TOSAVE
End Sub


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace Formatted Numbers with text 9 61
vb6 programatically bring window to front 8 63
MsgBox 2 47
bit defender blocks good applications 2 82
Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now