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
- For a start, trigger Outlook VBA editor by referring to “How to Run VBA Code in Your Outlook“.
- Then, in the new window, add the reference to “MS VBScript Regular Expressions” according to “How to Add an Object Library Reference in VBA“.
- 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 Next 'Open the Windows folder Call Shell("explorer.exe " & strFolder, vbNormalFocus) End If End If End Sub
- After that, add this macro to Quick Access Toolbar.
- Subsequently, select an email.
- Then, click the macro button in Quick Access Toolbar.
- Later, in the popup dialog box, select a Windows folder and click “OK”.
- Finally, the Windows folder will be displayed, like the following screenshot.
- Now, you can double click on the saved MHT files to open the 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 www.datanumen.com
Terrific Website, Preserve the great job. Appreciate it!
Much thanks! a really beneficial blog; couldn’t make
it without ya!
Tout d’abord bonjour…. Cet article est très utile.
je cherchais tout juste des infos sur le sujet. Bon courage!
Hi, I have followed every step but keep getting a
“Compile error: User-defined type not defined” message