Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do you save a file using InternetExplorer.Application?

3,906 views
Skip to first unread message

Jeff Fink

unread,
Feb 13, 2000, 3:00:00 AM2/13/00
to

I've got the script working to load a file and dump out the tags, but I want
to be able to save it to another file. How do I do this? Here's my script:

set IE = CreateObject("InternetExplorer.Application")
IE.visible = false
IE.silent = true

IE.navigate "file://x:/ie.htm", 12

wscript.echo "Len = " & IE.document.all.length

for each element in IE.document.all
wscript.echo element.tagName
next

IE.ExecWB 71, 0, "x:\\ie2.htm", ""


The error I get (on the last line) is:
X:\ie.vbs: Trying to revoke a drop target that has not been registered

Any ideas?
-Jeff

Michael Harris

unread,
Feb 13, 2000, 3:00:00 AM2/13/00
to
Where did you get the value 71? 
 
Try:
 
Const OLECMDID_SAVEAS = 4

--
Michael Harris
MVP - Windows Script
 
 
"Jeff Fink" <jfink...@yahoo.com> wrote in message news:e4Xt8Dld$GA.279@cppssbbsa04...

Jeff Fink

unread,
Feb 13, 2000, 3:00:00 AM2/13/00
to
I grabbed it from some header file somewhere.  Not too surprising I picked the wrong one since the docs aren't very good.
 
I put 4 in there, but IE never seems to save the file.  It just blocks.  My HTML file looks like this:
 
<HTML>
<HEAD>
    <TITLE>This is the title</TITLE>
</HEAD>
 
<BODY>
    This is the body.
</BODY>
</HTML
>
 
Both IE4.01 and IE5 get to the last line in the script and pause.  And pause.  And pause.  The new file doesn't even get created.  I'd be curious to know if the script works for anybody else.
Michael Harris wrote in message ...

Michael Harris

unread,
Feb 13, 2000, 3:00:00 AM2/13/00
to
It hangs because there's a SaveAs dialog box waiting.  You can't see it because you're running IE invisible.
 
I got a little farther with this:
 
=====================
 
html = "<HTML><HEAD><TITLE>This is the title</TITLE></HEAD><BODY>This is the body.</BODY></HTML>"

set IE = CreateObject("InternetExplorer.Application")
IE.visible = true
IE.navigate "about:" & html
while ie.busy:wend
 
wscript.echo "Len = " & IE.document.all.length
 
for each element in IE.document.all
    wscript.echo element.tagName
next

Const OLECMDID_SAVEAS = 4
Const OLECMDEXECOPT_DONTPROMPTUSER = 2

IE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER , "c:\ie2.htm"
 
======================
 
What's weird is that OLECMDEXECOPT_DONTPROMPTUSER doesn't keep you from being prompted but at least the passed file name is accepted.  But the language (in the SaveAs box) defaults to UNICODE.   That's OK for reopening in IE but is screwy if you open it in a non-UNICODE aware text editor.  And if you use OLECMDEXECOPT_DODEFAULT (value 0) then the file name defaults to the page title, not what you pass.

The moral of all this is: you may want to resort to getting the contents as text and saving it yourself.
 
strHTML = IE.document.body.parentElement.outerHTML
msgbox strHTML
 
Works ok for non-frames pages...
There have been several other threads over the last year about problems using ExecWB (all with printing I think) and none were successful (at least they never came back and said they finally got it to work ;-)...

--
Michael Harris
MVP - Windows Script
 
 
"Jeff Fink" <jfink...@yahoo.com> wrote in message news:OJykPKqd$GA.62@cppssbbsa04...

Jeff Fink

unread,
Feb 14, 2000, 3:00:00 AM2/14/00
to
Thanks for playing with this problem.  After turning visible on and looking at the stuff I figured I could write a simple app to get the window handle and send the appropriate messages to spoof UI input, but as it turns out the save as feature doesn't save what I want (it saves the original source of the page without any DOM changes I make to it).  I could do as you suggest and use the filesystem object to save the document's innerHTML property, but then I'm losing outer tags and I don't want to do that.
 
My real problem is that I want to attach an advertisement to the top of each page that is uploaded to my web site.  The upload is coming in via my own ISAPI extension so I have total control over the file.  I thought that there might be an easy scripting solution where I could just load the file and if the DOM parser didn't crap out, insert my ad object at the top and then resave the file.
 
Is there any easy way to do this?  If not, I'm just going to write the C code to parse the file as it comes in and insert my blob after the BODY tag (or before the first "sub-body" tag if there isn't a body tag, etc).
 
Thanks,
-Jeff

ted...@my-deja.com

unread,
Mar 6, 2000, 3:00:00 AM3/6/00
to
Hello,
What I do to bypass the prompt of SAVEAS with ExecWB is a SendKeys with
the path and a vbCrLf just before the ExecWB command.
Something like

SendKeys "c:\temp\test.html" & vbCrLf
IE.ExecWB ....

Works fine for me...
Greetings,
Ted


In article <erzA04qd$GA.270@cppssbbsa05>,
"Michael Harris" <Please...@To.NewsGroup> wrote:
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_104C_01BF766A.F24E6C60
> Content-Type: text/plain;
> charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable


>
> It hangs because there's a SaveAs dialog box waiting. You can't see

it =


> because you're running IE invisible.
>
> I got a little farther with this:
>

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> html =3D "<HTML><HEAD><TITLE>This is the
title</TITLE></HEAD><BODY>This =


> is the body.</BODY></HTML>"
>

> set IE =3D CreateObject("InternetExplorer.Application")
> IE.visible =3D true
>
> IE.navigate "about:" & html=20
> while ie.busy:wend
>
> wscript.echo "Len =3D " & IE.document.all.length


>
> for each element in IE.document.all
> wscript.echo element.tagName
> next
>

> Const OLECMDID_SAVEAS =3D 4
> Const OLECMDEXECOPT_DONTPROMPTUSER =3D 2


>
> IE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER , "c:\ie2.htm"
>

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


>
> What's weird is that OLECMDEXECOPT_DONTPROMPTUSER doesn't keep you

from =


> being prompted but at least the passed file name is accepted. But the

=
> language (in the SaveAs box) defaults to UNICODE. That's OK for =


> reopening in IE but is screwy if you open it in a non-UNICODE aware

text =


> editor. And if you use OLECMDEXECOPT_DODEFAULT (value 0) then the

file =


> name defaults to the page title, not what you pass.
>
> The moral of all this is: you may want to resort to getting the

contents =


> as text and saving it yourself.
>

> strHTML =3D IE.document.body.parentElement.outerHTML


> msgbox strHTML
>
> Works ok for non-frames pages...
>
> There have been several other threads over the last year about

problems =


> using ExecWB (all with printing I think) and none were successful (at

=


> least they never came back and said they finally got it to work ;-)...
>

> --=20


> Michael Harris
> MVP - Windows Script
>

> "Jeff Fink" <jfink...@yahoo.com> wrote in message =
> news:OJykPKqd$GA.62@cppssbbsa04...
> I grabbed it from some header file somewhere. Not too surprising I =


> picked the wrong one since the docs aren't very good.

> =20


> I put 4 in there, but IE never seems to save the file. It just

blocks. =


> My HTML file looks like this:

> =20


> <HTML>
> <HEAD>
> <TITLE>This is the title</TITLE>
> </HEAD>

> =20


> <BODY>
> This is the body.
> </BODY>
> </HTML>

> =20


> Both IE4.01 and IE5 get to the last line in the script and pause. And

=
> pause. And pause. The new file doesn't even get created. I'd be =


> curious to know if the script works for anybody else.
> Michael Harris wrote in message ...

> Where did you get the value 71? =20
> =20
> Try:
> =20
> Const OLECMDID_SAVEAS =3D 4
>
> --=20


> Michael Harris
> MVP - Windows Script
>

> =20
> "Jeff Fink" <jfink...@yahoo.com> wrote in message =


> news:e4Xt8Dld$GA.279@cppssbbsa04...
>
> I've got the script working to load a file and dump out the tags,

but =


> I want
> to be able to save it to another file. How do I do this? Here's my

=
> script:
>
> set IE =3D CreateObject("InternetExplorer.Application")
> IE.visible =3D false
> IE.silent =3D true


>
> IE.navigate "file://x:/ie.htm", 12
>

> wscript.echo "Len =3D " & IE.document.all.length


>
> for each element in IE.document.all
> wscript.echo element.tagName
> next
>
> IE.ExecWB 71, 0, "x:\\ie2.htm", ""
>
> The error I get (on the last line) is:
> X:\ie.vbs: Trying to revoke a drop target that has not been
registered
>
> Any ideas?
> -Jeff
>

> ------=_NextPart_000_104C_01BF766A.F24E6C60
> Content-Type: text/html;
> charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META content=3D"text/html; charset=3Dwindows-1252" =
> http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
=
> Transitional//EN">
> <META content=3D"MSHTML 5.00.3013.2600" name=3DGENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=3D#ffffff>
> <DIV><FONT size=3D2>It hangs because there's a SaveAs dialog box =
> waiting.&nbsp;=20
> You can't see it because you're running IE invisible.</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>I got a little farther with this:</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT =
>
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
<=
> /FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>html =3D
"&lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt;This =
> is the=20
> title&lt;/TITLE&gt;&lt;/HEAD&gt;&lt;BODY&gt;This is the=20
> body.&lt;/BODY&gt;&lt;/HTML&gt;"</FONT></DIV>
> <DIV><FONT size=3D2><BR>set IE =3D=20
> CreateObject("InternetExplorer.Application")<BR>IE.visible =3D=20
> true<BR></DIV></FONT>
> <DIV><FONT size=3D2>IE.navigate "about:" &amp; html <BR>while=20
> ie.busy:wend</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>wscript.echo "Len =3D " &amp;=20
> IE.document.all.length</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>for each element in =
> IE.document.all<BR>&nbsp;&nbsp;&nbsp;=20
> wscript.echo element.tagName<BR>next</FONT></DIV>
> <DIV><FONT size=3D2><BR>Const OLECMDID_SAVEAS =3D 4<BR>Const=20
> OLECMDEXECOPT_DONTPROMPTUSER =3D 2</FONT></DIV>
> <DIV><FONT size=3D2><BR>IE.ExecWB OLECMDID_SAVEAS, =
> OLECMDEXECOPT_DONTPROMPTUSER ,=20
> "c:\ie2.htm"</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT =
>
size=3D2>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=
> </FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>What's weird is that OLECMDEXECOPT_DONTPROMPTUSER
=
> doesn't keep=20
> you from being prompted but at least the passed file name is =
> accepted.&nbsp; But=20
> the language (in the SaveAs box) defaults to UNICODE.&nbsp;&nbsp;
That's =
> OK for=20
> reopening in IE but is screwy if you open it in a non-UNICODE =
> aware&nbsp;text=20
> editor.&nbsp; And if you use OLECMDEXECOPT_DODEFAULT (value 0) then
the =
> file=20
> name defaults to the page title, not what you pass.</FONT></DIV>
> <DIV><FONT size=3D2><BR>The moral of all this is: you may want to
resort =
> to=20
> getting the contents as text and saving it yourself.</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2>strHTML =3D =
> IE.document.body.parentElement.outerHTML<BR>msgbox=20
> strHTML</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Works ok for non-frames pages...<BR></DIV></FONT>
> <DIV><FONT size=3D2>There have been several other threads over the
last =
> year about=20
> problems using ExecWB (all with printing I think) and none were =
> successful (at=20
> least they never came back and said they finally got it to work=20
> ;-)...</DIV></FONT>
> <DIV><BR>-- <BR>Michael Harris<BR>MVP - Windows Script</DIV>
> <DIV>&nbsp;</DIV>
> <DIV>&nbsp;</DIV>
> <DIV>"Jeff Fink" &lt;<A=20
> href=3D"mailto:jfink...@yahoo.com">jfink...@yahoo.com</A>&gt;
wrote =
> in message=20
> <A=20
>
href=3D"news:OJykPKqd$GA.62@cppssbbsa04">news:OJykPKqd$GA.62@cppssbbsa04
<=
> /A>...</DIV>
> <DIV><FONT color=3D#000000 size=3D2>I grabbed it from some header
file=20
> somewhere.&nbsp; Not too surprising I picked the wrong one since the =
> docs aren't=20
> very good.</FONT></DIV>
> <DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>I put 4 in there, but IE never seems to save the =
> file.&nbsp;=20
> It just blocks.&nbsp; My HTML file looks like this:</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT
size=3D2>&lt;HTML&gt;<BR>&lt;HEAD&gt;<BR>&nbsp;&nbsp;&nbsp;=20
> &lt;TITLE&gt;This is the =
> title&lt;/TITLE&gt;<BR>&lt;/HEAD&gt;</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>&lt;BODY&gt;<BR>&nbsp;&nbsp;&nbsp; This is the=20
> body.<BR>&lt;/BODY&gt;<BR>&lt;/HTML</FONT><FONT =
> size=3D2>&gt;</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Both IE4.01 and IE5 get to the last line in the =
> script and=20
> pause.&nbsp; And pause.&nbsp; And pause.&nbsp; The new file doesn't
even =
> get=20
> created.&nbsp; I'd be curious to know if the script works for
anybody=20
> else.</FONT></DIV>
> <BLOCKQUOTE=20
> style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px;
PADDING-LEFT: =
> 5px">
> <DIV>Michael Harris<PLEASE...@TO.NEWSGROUP> wrote in=20
> message<ECW#QIOD$GA.201@CPPSSBBSA05> ...</DIV>
> <DIV><FONT size=3D2>Where did you get the value 71?&nbsp; =
> </FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Try:</FONT></DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT size=3D2>Const OLECMDID_SAVEAS =3D 4</FONT></DIV>
> <DIV><FONT size=3D2><BR>-- <BR>Michael Harris<BR>MVP - Windows=20
> Script</FONT></DIV>
> <DIV>&nbsp;</DIV>
> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
> <DIV>"Jeff Fink" &lt;<A=20
> href=3D"mailto:jfink...@yahoo.com">jfink...@yahoo.com</A>&gt; =
> wrote in=20
> message <A=20
> =
>
href=3D"news:e4Xt8Dld$GA.279@cppssbbsa04">news:e4Xt8Dld$GA.279@cppssbbsa
0=
> 4</A>...</DIV><BR>I've=20
> got the script working to load a file and dump out the tags, but I =
> want<BR>to=20
> be able to save it to another file.&nbsp; How do I do this?&nbsp; =
> Here's my=20
> script:<BR><BR>set IE =3D=20
> CreateObject("InternetExplorer.Application")<BR>IE.visible =3D=20
> false<BR>IE.silent =3D true<BR><BR>IE.navigate "<A=20
> href=3D'file://x:/ie.htm"'>file://x:/ie.htm"</A>, =
> 12<BR><BR>wscript.echo "Len =3D=20
> " &amp; IE.document.all.length<BR><BR>for each element in=20
> IE.document.all<BR>&nbsp;&nbsp;&nbsp; wscript.echo=20
> element.tagName<BR>next<BR><BR>IE.ExecWB 71, 0, "x:\\ie2.htm",=20
> ""<BR><BR><BR>The error I get (on the last line) is:<BR>X:\ie.vbs: =
> Trying to=20
> revoke a drop target that has not been registered<BR><BR>Any=20
> ideas?<BR>-Jeff<BR><BR></BLOCKQUOTE></BODY></HTML>
>
> ------=_NextPart_000_104C_01BF766A.F24E6C60--
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages