VBA Code for webpage save as MHT file

krishnaoptif

Board Regular
Joined
Sep 17, 2010
Messages
140
I want o write a vba code for below: I want to download and saves a list of webpages (and contents like images, animated GIFs, sounds, videos,...) as MHT Files (1 MHT file for each link from the list). In the below files there's an example of how it should look like.



I am familiar with the URLDownloadToFile function, but it doesn't download the webpage's contents. What I need is something like a URLDownloadToMHT function that downloads the entire webpage and its contents and packs it into a MHT file. The MHT file, obviously, needs to link the content files locally for offline browsing (I don't know exactly how a MHT file works, but what I mean is that src="http://www...file.jpg" should be replaced by src="file.jpg", something like that)

I am also familiar with softwares like WinHTTrack, that do something similar(with HTML files), but I think the downloaded files get too messy and disorganized, that's why I need something simple like MHT files saved in a folder of my choice.
I need this Excel file to work in any Windows XP/Windows 7 computer, without dependencies from other files like third-party dll's or any other files.

May you pleas provide me VBA code line for above..
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hope you know that static saved web-page is not the same as the dynamic original one.
Save manually via the browser as MHT any web-page from your list and open that saved copy to see the differences.

You can start with the below code to save web-page as MHT file:
Rich (BB code):
Sub Test()
  UrlToMht "http://9gag.com/gag/4628225", "c:\Temp\1.mht"
End Sub
 
Sub UrlToMht(Url As String, Mht As String)
' ZVI:2014-02-13 http://www.mrexcel.com/forum/excel-questions/757383-visual-basic-applications-code-webpage-save-mht-file.html
  With CreateObject("CDO.Message")
    .MimeFormatted = True
    .CreateMHTMLBody Url, 0, "", ""
    .GetStream.SaveToFile Mht, 2
  End With
End Sub
 
Upvote 0
Hope you know that static saved web-page is not the same as the dynamic original one.
Save manually via the browser as MHT any web-page from your list and open that saved copy to see the differences.

You can start with the below code to save web-page as MHT file:
Rich (BB code):
Sub Test()
  UrlToMht "http://9gag.com/gag/4628225", "c:\Temp\1.mht"
End Sub
 
Sub UrlToMht(Url As String, Mht As String)
' ZVI:2014-02-13 http://www.mrexcel.com/forum/excel-questions/757383-visual-basic-applications-code-webpage-save-mht-file.html
  With CreateObject("CDO.Message")
    .MimeFormatted = True
    .CreateMHTMLBody Url, 0, "", ""
    .GetStream.SaveToFile Mht, 2
  End With
End Sub






This is already resolved. Now what action reqired?
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,021
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top