How to Quickly Save the Web Pages of All URLs in an Outlook Email to a Windows Folder

After receiving an email which contains several URLs in body, you will usually open the corresponding web pages of the URLs. Now, if you want to batch save these web pages to a Windows folder as MHT or HTML files, you can use the way in this post.

In order to easily access important web pages, you can directly save them to local drive as MHT or HTML files. Now, if you’ve received an Outlook mail containing a lot of significant URLs, aside from exporting the URL list to an Excel sheet, you may also want to save the web pages of these URLs to a local folder. Thereinafter, we will help you achieve it with VBA code effortlessly.

Save the Web Pages of All URLs in an Email to a Windows Folder

  1. For a start, trigger Outlook VBA editor by referring to “How to Run VBA Code in Your Outlook“.
  2. Then, in the new window, add the reference to “MS VBScript  Regular Expressions” according to “How to Add an Object Library Reference in VBA“.
  3. Next, copy the following VBA code into a module.
Sub SaveWebPages_URLs_Email()
    Dim objMail As Outlook.MailItem
    Dim objRegExp As RegExp
    Dim strFolder As String
    Dim objMatchCollection As MatchCollection
    Dim objMatch As Match
    Dim strURL As String
    Dim objShell As Object
    Dim objWindowsFolder As Object
    Dim strMHTFile As String
    'Get the source mail
    Select Case Outlook.Application.ActiveWindow.Class
           Case olInspector
                Set objMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set objMail = ActiveExplorer.Selection.Item(1)
    End Select

   'Get URLs using regular expression
    Set objRegExp = New RegExp
    With objRegExp
         .Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$;_])*)"
         .Global = True
         .IgnoreCase = True
    End With
    If objRegExp.Test(objMail.Body) Then
       'Choose a Windows folder
       Set objShell = CreateObject("Shell.Application")
       Set objWindowsFolder = objShell.BrowseForFolder(0, "Select a Windows Folder:", 0, "")
       If Not objWindowsFolder Is Nothing Then
          strFolder = objWindowsFolder.self.Path & "\" & objMail.Subject & "\"
          MkDir (strFolder)
          Set objMatchCollection = objRegExp.Execute(objMail.Body)
          i = 0
          For Each objMatch In objMatchCollection
              strURL = objMatch.SubMatches(0)

              i = i + 1
              strMHTFile = strFolder & "URLs-" & i & ".mht"
              'Save web pages as MHT files
              With CreateObject("CDO.Message")
                  .MimeFormatted = True
                  .CreateMHTMLBody strURL, 0, "", ""
                  .GetStream.SaveToFile strMHTFile, 2
              End With
          'Open the Windows folder
          Call Shell("explorer.exe " & strFolder, vbNormalFocus)
       End If
    End If
End Sub

VBA Code - Save the Web Pages of All URLs in an Email to a Windows Folder

  1. After that, add this macro to Quick Access Toolbar.
  2. Subsequently, select an email.
  3. Then, click the macro button in Quick Access Toolbar.Click Macro Button
  4. Later, in the popup dialog box, select a Windows folder and click “OK”.Select Windows Folder
  5. Finally, the Windows folder will be displayed, like the following screenshot.Saved MHT Files
  6. Now, you can double click on the saved MHT files to open the web pages.Opened Web Pages

What If PST File Gets Damaged

If you’re so unfortunate that your PST file becomes inaccessible, what would you then? Generally speaking, you can make use of inbox repair tool to attempt PST fix. Yet, at times, it will fail. At that point, you have to resort to a more experienced external utility, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf fix and outlook repair software products. For more information visit

4 responses to “How to Quickly Save the Web Pages of All URLs in an Outlook Email to a Windows Folder”

  1. Hi, I have followed every step but keep getting a
    “Compile error: User-defined type not defined” message