If IE.ConnectToNewObject("InternetExplorer.Application")
<> 0 Then
Messagebox("Error:","Please check, Excel is properly
installed at this system")
destroy IE
Return
End If
IE.navigate("C:\Documents and
Settings\dhruv\Desktop\temp123.htm")
IE.visible = false
IE.Document.execCommand("SaveAs", 1, "C:\Documents and
Settings\dhruv\Desktop\foo.htm")
IE.disconnectobject()
destroy IE
>I want to saveas silently ! it will not prompt to user for
>saveas please tell me how can I do this silently.
I'm trying too to save the currently displayed web page into a mht file on the hd.
I've tried both document.execcommand and execwb:
const OLECMDID_SAVEAS = 4
const OLECMDEXECOPT_DONTPROMPTUSER=2
oIE.document.execCommand "SaveAs", false, "c:\ExecCommand.htm"
oIE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, "c:\ExecWB.htm"
but:
1) both commands ask for confirmation with a "save as " window. I would like the program
to run with no interaction.
2) in both cases I can only choose between pure .htm and .txt. No mht available, nor the
htm with the related files' folder.
I've tried xmlhttp (thanks to Tom Lavedas) but it downloads only the file specified. Good
for pdf, not for pages with images. But if you download with "navigate" the images are
stored in the cache and can be retrived automatically when opening the page saved with
xmlhttp.
The code for xmlhttp is the following. It uses ADODB to save the response stream to a
file.
Sub DownloadWithXMLHTTP (sSource,sDest)
'Download a file using activeX Object XMLHTTP
'and save to sDest using ADO Stream
set oHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
oHTTP.open "GET", sSource, False
oHTTP.send
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write oHTTP.responseBody
oStream.savetofile sDest, adSaveCreateOverWrite
set oStream = nothing
set oHTTP = nothing
end sub
--
Giovanni Cenati (Aosta, Italy)
Write to user "nnever" and domain "@katamail.com"
Anyway, this is the script I use to get pages from the internet.
In a file called BATCBROWSER2.TXT I put the urls.
The file should contain lines as
http://www.url.it/index.htm
or
http://www.url.it/index.htm local filename where to save this page.htm
or
http://www.url.it/catalog.pdf Catalog of url.it.PDF
Try it and let me know.
Giovanni.
'<%
'BatchBrowser.vbs
'Richiede le pagine web specificate in un file chiamato "BatchBrowser.txt".
'Apre il file, legge tutte le righe e le mette in un array.
'Poi lancia Internet Explorer e richiede le singole pagine,
'aggiungendo http se manca prima del nome del sito.
'Le pagine caricate resteranno poi nella cronologia e potranno
'essere visualizzate off-line. Non funziona con alcune pagine
'create dinamicamente, a meno che siano l'ultima pagina caricata,
'nel qual caso rimangono visualizzate al termine dello script.
'[c] Cenati Giovanni 12.03.02 nne...@katamail.com
const OLECMDID_SAVEAS = 4
const OLECMDID_ALLOWUILESSSAVEAS = 46
const OLECMDEXECOPT_DONTPROMPTUSER=2
Dim oIE
file = "BatchBrowser2.txt"
title = "BatchBrowser - Cenati"
set fso= createobject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
Set txtStream = fso.OpenTextFile(file) ' Apre file di testo.
txt = txtStream.ReadAll 'legge tutto il file
txtStream.Close 'lo chiude
lines = Split(txt, vbCrLf) 'Crea un array delle linee del file
Else ' Termina.
MsgBox "File '" & file & "' non trovato", vbOKOnly + vbCritical, Title
WScript.Quit 1 ' Termina con error code 1.
End If
' Crea un oggetto Internet Explorer
Set oIE = WScript.CreateObject("InternetExplorer.Application")
' Setta le proprietà della finestra del browser
oIE.left = 20 ' La finestra
oIE.top = 50 ' in alto a sinistra,
oIE.height = 380 ' piccola...
oIE.width = 580
oIE.menubar = 0 ' Senza menu
oIE.toolbar = 0 ' né barra degli strumenti
oIE.statusbar = 0 ' né barra di stato per essere più riconoscibile.
oIE.navigate("about:blank") ' Crea un documento HTML vuoto.
oIE.visible = 1
for i = 0 to ubound(lines)
if trim(lines(i))<>"" then 'Se non è una riga vuota...
URL=EstraiUrl( lines(i))
Filename=EstraiFileName (lines(i))
if FileName<>"" then
DownloadWithXMLHTTP URL, Filename
else
DownloadWithIE URL
end if 'Filename non vuoto
end if 'Riga non vuota
next 'Passa alla prossima pagina
set oIE=nothing
'*** End
wscript.quit
Function EstraiUrl (riga)
'Da una riga composta da URL[blank]FileName estrae la prima parte.
'Se non c'é, aggiunge http prima del testo.
if ucase(left(riga,7))<>"HTTP://" then
riga="HTTP://" & trim(riga) 'aggiunge "http://" se manca
end if
Separa = inStr(1,riga," ") 'Trova il primo spazio
EstraiUrl=riga
if Separa=0 then exit function 'Se non c'è lo spazio restituisce "riga"
URL= left(lines(i),Separa-1) 'Prima dello spazio c'è l'URL
EstraiUrl=URL
end function
Function EstraiFileName(riga)
Separa = inStr(1,riga," ") 'Trova il primo spazio
EstraiFilename=""
if Separa=0 then exit function
EstraiFileName= right(riga, len(riga)-Separa)
'Dopo lo spazio c'è iriganome del file
end function
Sub DownloadWithXMLHTTP (sSource,sDest)
'Download a file using activeX Object XMLHTTP
'and save to sDest using ADO Stream
set oHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
oHTTP.open "GET", sSource, False
oHTTP.send
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write oHTTP.responseBody
oStream.savetofile sDest, adSaveCreateOverWrite
set oStream = nothing
set oHTTP = nothing
end sub
Sub DownloadWithIE(sURL)
oIE.navigate(sURL) 'Richiede la pagina in internet
Do While(oIE.Busy): WScript.Sleep 1000 :Loop
WScript.Sleep 1000
Do While(oIE.Busy): WScript.Sleep 1000 :Loop
' Aspetta che IE abbia caricato la pagina. Sleep libera risorse al sistema.
' Serve anche per aspettare le pagine che caricano altre pagine automaticamente.
'oIE.document.execCommand "SaveAs", false, "c:\ExectCommand.htm"
'oIE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, "c:\ExecWB.htm"
'Salva la pagina