Welcome to Scripting Forums Sign in | Join | Help
in Search

An easy VBS just to save a web-page to MHT...

Last post 11-25-2007, 9:27 AM by asgarcymed. 4 replies.
Sort Posts: Previous Next
  •  10-25-2007, 8:49 PM 28735

    An easy VBS just to save a web-page to MHT...

    I want to create an easy VBS to save a web-page to MHT (MHTML). I saw many examples through a google's search, but they were very confusing because all of them also intended to send an eMail after saving the MIME file. I just want to save a web-page to MHT; not to send eMail!! Here are some "fragments of code" I saw: Set cdo_msg = CreateObject ("CDO.Message") Set ado_stream = CreateObject ("ADODB.Stream") .CreateMHTMLBody .GetStream .DataSource.SaveToObject .SaveToFile Can you please help me to make an easy VBS just to save a web-page to MHT? All examples seems to be totally wrong (I tried copy-paste and always got errors). Here is one: Set cdo_message_object = CreateObject("CDO.Message") Set stream_ado_object = CreateObject("ADODB.Stream") cdo_message_object.CreateMHTMLBody "http://en.wikipedia.org/wiki/Array", 0, "","" stream_ado_object.GetStream stream_ado_object.SaveToFile "C:\array.mht" The line cdo_message_object.CreateMHTMLBody (...) always gives error!!! I tried: cdo_message_object.CreateMHTMLBody "http://en.wikipedia.org/wiki/Array", 0, "","" cdo_message_object.CreateMHTMLBody (http://en.wikipedia.org/wiki/Array, 0, "","") cdo_message_object.CreateMHTMLBody ("http://en.wikipedia.org/wiki/Array", 0, "","") None worked :( What a great mystery!!!!! Take a look at this VBS: 'MakeMHT.vbs Const adSaveCreateNotExist = 1 Const adSaveCreateOverWrite = 2 Const adTypeBinary = 1 'Binary data Const adTypeText = 2 '(Default) Text data URL = "http://www.paulsadowski.com/" DiskFile = "C:\test.mht" Set objMessage = CreateObject("CDO.Message") objMessage.CreateMHTMLBody URL SaveToFile objMessage, DiskFile Sub SaveToFile(Msg, Fn) Dim Strm, Dsk Set Strm = CreateObject("ADODB.Stream") Strm.Type = adTypeText Strm.Charset = "US-ASCII" Strm.Open Set Dsk = Msg.DataSource Dsk.SaveToObject Strm, "_Stream" Strm.SaveToFile Fn, adSaveCreateOverWrite End Sub This works fine. Now look at this one (everything is the same, except the URL itself): 'MakeMHT.vbs Const adSaveCreateNotExist = 1 Const adSaveCreateOverWrite = 2 Const adTypeBinary = 1 'Binary data Const adTypeText = 2 '(Default) Text data URL = "http://www.yahoo.com/" DiskFile = "C:\test.mht" Set objMessage = CreateObject("CDO.Message") objMessage.CreateMHTMLBody URL SaveToFile objMessage, DiskFile Sub SaveToFile(Msg, Fn) Dim Strm, Dsk Set Strm = CreateObject("ADODB.Stream") Strm.Type = adTypeText Strm.Charset = "US-ASCII" Strm.Open Set Dsk = Msg.DataSource Dsk.SaveToObject Strm, "_Stream" Strm.SaveToFile Fn, adSaveCreateOverWrite End Sub Why the hell this second scripts causes an error - «(12,1) CDO.Message.1: Invalid syntax»?????????? Everything is exactly the same except: URL = "http://www.paulsadowski.com/" => => URL = "http://www.yahoo.com/"
  •  10-25-2007, 8:53 PM 28736 in reply to 28735

    Re: An easy VBS just to save a web-page to MHT...

    This is unreadable!! Why this destroyed my text format? Now everything is joined; what a confusion!! How can I post text with paragraphs?
  •  10-25-2007, 9:00 PM 28737 in reply to 28736

    Re: An easy VBS just to save a web-page to MHT...

    I have never seen such thing - a forum system that kills text format and then turns everything unreadable! Please take a look at: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_22915834.html and/or http://www.visualbasicscript.com/m_53000/mpage_1/key_/tm.htm#53027 I don't know why but no one seems to able to give me a good answer... Is this so much difficult? My ignorance doesn't distinguish... Please help me; I really need to get this answer! Thanks in avdance. Best regards!
  •  11-01-2007, 3:19 PM 28759 in reply to 28737

    Re: An easy VBS just to save a web-page to MHT...

    Hi asgarcymed, 

    Here's a blog post that Jeff Hicks at scriptinganswers.com found:

    http://www.goldb.org/goldblog/CommentView,guid,19ce47f2-b118-4522-8cc6-ff1b7b10b942.aspx

    Bill

  •  11-25-2007, 9:27 AM 28912 in reply to 28759

    Re: An easy VBS just to save a web-page to MHT...

    Thank you!

    Best regards.

View as RSS news feed in XML
SPONSORED LINKS FEATURED LINKS

Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Microsoft Learning Snack - Green IT Through Virtualization Many organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. Order Your Fundamentals CD Today!Register today for your in-depth copy of one of three Fundamental CDs on the following topics – Exchange, SQL, and SharePoint. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization BasicsWith virtualization, computing components essentially become on-demand services, freeing each element of a system from the others. This short video explains the needs, benefits, and technologies behind virtualization. Microsoft Learning Snack - Virtualization With Windows Server 2008Windows Server 2008 includes virtualization technology that allows many operating systems - including open source - to run on a single host. Come learn the basics of implementing these features. Empower Your Processes with PowerShell 201Paul Robichaux delves deep into PowerShell how-tos in 3 informative lessons, each followed by live Q&A—all on your own computer! Register today! Microsoft Learning Snack - Green IT Through VirtualizationMany organizations face rising operating costs caused by excessive energy consumption. Virtualization and "Green IT" can help cut these costs. Get the information you need to bring Green IT savings to your business. New Release: Windows IT Pro Master CD13 years of content archives, fast answers with advanced search tools, and full access to WindowsITPro.com—order today!

 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing