Option ExplicitContoh pemanggilan prosedur fungsi di atas:
Public Function SaveWebPageToMHTFile(url As String, filepath As String)
On Error GoTo ErrHandler
Dim msg As New CDO.Message
Dim stm As New ADODB.Stream
msg.MimeFormatted = True
msg.CreateMHTMLBody url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", ""
'//Pilih charset yang sesuai
stm.Charset = "utf-8"
Set stm = msg.GetStream()
stm.SaveToFile filepath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite
Set msg = Nothing
stm.Close
Exit Function
ErrHandler:
MsgBox Err.Description
End Function
Private Sub Command1_Click()
'//Coba menyimpan file dalam bentuk MHTML </i>
SaveWebPageToMHTFile "http://www.planet-source-code.com/vb/default.asp?lngWId=1", "c:\psc.MHTML"
End Sub
Catatan: Sebelum Anda menggunakan fungsi di atas, tambahkan referensi Microsoft ActiveX Data Objects 2.8 Liblary dan Microsoft CDO for Windows 2000 Liblary