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

Free Download –VS 2008 TrainingExperts Ken Getz & Robert Green plus labs, code, courseware Maximize speed, performance and reliablity of your PCs and servers—automatically!Speed Up Your PC! Try Diskeeper 2008 with InvisiTasking Free Now! Register for SolarWinds VM MonitorGet X-Ray Vision into Your ESX Servers with SolarWinds FREE VM Monitor GoGrid Offers FREE Trial for Windows Cloud ServersDeploy Windows Server 2003 and 2008 with free load balancing through GoGrid’s award winning web-based GUI – all in less than 5 minutes Order Your SQL Fundamentals CD Today! Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD. How healthy is your Exchange Server? Find out Now!Automatic Exchange Server Maintenance helps prevent disasters and improves performance. Download a FREE Exchange Server analysis tool. You've Deployed SharePoint...Now What?This one-day free online conference delivers the technical knowledge needed to kick MOSS up a notch. In one information-packed day, independent SharePoint experts will present practical, real-world information and provide take-away, ready-to-use solutions Ease Your Scripting Pains with the Flexibility of PowerShell!Paul Robichaux equips you with PowerShell basics in 3 introductory lessons, each followed by live Q&A—all on your own computer! Register today! What Would You Do If You Ran Microsoft?ITTV's 2008 inaugural video contest, "If I Ran Microsoft..." is your chance to tell it like it is. Be goofy or be serious, but don"t miss this chance to have fun, win prizes, and go viral in a major way. Maximize Your SharePoint InvestmentThis web seminar discusses how true bi-directional replication of SharePoint content from one server to another enables branch offices to maintain access to current SharePoint content. Rock Your Knowledge, and Compete with Friends and Colleagues!Are you the Web Application Performance Guru in your office? It's time to have fun! Download now to access the crossword puzzle. Challenge yourself and complete this fun activity!

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