Internet Explorer Save Tabs

This little demo demonstrates how you can iterate through all your open Internet Explorer windows/tabs and save the information to an Access table.  I find this to be much more powerful than bookmarks, etc.

In Access this information can be grouped, searched, sorted, … Simply put, used much more easily.

This can be a great tools to share useful links between team members. You can build a treasure trove of useful links by topic and then share them with everyone in this manner.

The code, is not necessarily Access centric, beyond the saving to a table, which is a single INSERT into query.  Beyond that, the functionality could easily be integrated into any other VBA programs (Excel, PowerPoint, Word, …).

Although the code was developed on Access 32-bit, it uses no APIs, etc. so it can be ported to 64-bit without any issue.

The heart of the entire database is actually a single, simple function:

'---------------------------------------------------------------------------------------
' Procedure : SaveIETabs
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Iterates through all the IE Tabs and saves the info (URL, Title, ...) to a
'               table for later retrieval
' Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773974(v=vs.85).aspx
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: 100% Pure VBA, No APIs, so none required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' bCloseTabs: TRUE/FALSE should the window/tab be closed after import
' frm       : Form object to requery after the import to update the displayed data
'
' Usage:
' ~~~~~~
' lNoTabs = SaveIETabs(True, Me)
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2017-02-03              Initial Release
' 2         2018-09-20              Updated Copyright
'---------------------------------------------------------------------------------------
Function SaveIETabs(ByVal bCloseTabs As Boolean, Optional frm As Access.Form) As Long
    On Error GoTo Error_Handler
    Dim oShell                As Object
    Dim oWindows              As Object
    Dim oWindow               As Object
    Dim oIE                   As Object
    Dim db                    As DAO.Database
    Dim sSQL                  As String
    Dim i                     As Variant    'must be variant to work???! Even though Count return an Integer
    Dim j                     As Long

    Set oShell = CreateObject("Shell.Application")
    Set oWindows = oShell.Windows
    Set db = CurrentDb

    '    For Each oWindow In oWindows
    For i = (oWindows.Count - 1) To 0 Step -1    'Because I'm closing them, better to go backwards
        Set oWindow = oWindows.Item(i)
        If (InStr(1, oWindow, "Internet Explorer", vbTextCompare)) Then
            j = j + 1
            With oWindow
                '                Debug.Print j, .Hwnd, .Name, .LocationURL, .Document.Title
                sSQL = "INSERT INTO IETabs" & vbCrLf & _
                       " (EntryDate, Hwnd, PageURL, PageTitle)" & vbCrLf & _
                       " VALUES(#" & Now() & "#, " & .Hwnd & ", '" & SanitizeQuotes(.LocationURL) & _
                       "', '" & SanitizeQuotes(.Document.Title) & "')"
                db.Execute sSQL

                'At this point we could bind to the instance to work with it if we so chose
                'Close the tab if so desired
                If bCloseTabs = True Then
                    Set oIE = oWindow
                    '                Debug.Print , , , , oIE.LocationURL
                    oIE.Quit    'Closes the tab after saving it
                End If
            End With
        End If
    Next
    
    If Not frm Is Nothing Then frm.Requery 'Requery the calling form, if one is passed, to show the new entries
    
    SaveIETabs = j

Error_Handler_Exit:
    On Error Resume Next
    If Not db Is Nothing Then Set db = Nothing
    If Not oIE Is Nothing Then Set oIE = Nothing
    If Not oWindow Is Nothing Then Set oWindow = Nothing
    If Not oWindows Is Nothing Then Set oWindows = Nothing
    If Not oShell Is Nothing Then Set oShell = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: SaveIETabs" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

and as you can see in the above procedure, we are binding to IE, so you could push automation much further if so desired.

Disclaimer/Notes:

If you do not have Microsoft Access, simply download and install the freely available runtime version (this permits running MS Access databases, but not modifying their design):

Microsoft Access 2010 Runtime
Microsoft Access 2013 Runtime
Microsoft Access 2016 Runtime
Microsoft 365 Access Runtime

All code samples, download samples, links, ... on this site are provided 'AS IS'.

In no event will Devhut.net or CARDA Consultants Inc. be liable to the client/end-user or any third party for any damages, including any lost profits, lost savings or other incidental, consequential or special damages arising out of the operation of or inability to operate the software which CARDA Consultants Inc. has provided, even if CARDA Consultants Inc. has been advised of the possibility of such damages.

Also note, that this is merely a simple demo to illustrate keep concepts and functionalities. Before moving it into production, proper error handling should be added throughout, variable validation needs to be enforced and testing of the overall application needs to be performed.

Download (V1.00)

Feel free to download a copy (accdb x32) by using the link provided below:

Download “Internet Explorer Save Tabs (accdb x32)” IE_SaveTabs_V1.00.zip – Downloaded 6135 times – 59.54 KB

Purchase (V1.01)

Want more features!

  • Would you like to be able to easily search through your list of URLs at the click of a button!
  • Would you like to be able to reopen a specific webpage at the click of a button!
  • Would you like to be able to reopen an entire Internet Explorer session (multiple tabs or windows) at the click of a button!

Internet Explorer Save Tabs (accdb x32) (4406 downloads )

Version History

V1.01 (2017-02-03)

  • Added search abilities
  • Added open webpage
  • Added the ability to restore a complete session
  • Code cleanup and optimization

V1.00 (2017-02-03)

  • Initial release

4 responses on “Internet Explorer Save Tabs

  1. azer

    could you check the zip file .. 52 kb seems too small , and the zip is corrupt..
    if i save the procedure and in the execution Windows i write : =SaveIETabs(True, Me)
    shouldn’t it work ?

    thanks

    1. Daniel Pineault Post author

      I’ve re-uploaded the zip to the site and tested it. Everything seems in order. Let me know if you experience any further issues.

      And yes, the zip file is around 60KB. It’s a simple db.

  2. FAB1

    Hi Daniel, I was trying to figure out how to get your example to pull through the url from a forms webbrowser control. Would this be possible?

    1. Daniel Pineault Post author

      I’m sorry but I’m not following the question. Could you explain to me some more what you are wishing to do? Maybe give me a concrete example and I’ll see if I can help you.