Basically, I want to use <style>...</style>.
Below is an example that fails because "Document.Head" is invalid.
Thanks in advance.
Option Explicit
Dim strIE1
strIE1 = ""
strIE1 = strIE1 & "<style type='text/css'>"
strIE1 = strIE1 & " td { font-size:64pt }"
strIE1 = strIE1 & " th { font-size:64pt; font-weight:bold }"
strIE1 = strIE1 & ".xx { font-size:64pt; font-weight:bold }"
strIE1 = strIE1 & "</style>"
Dim strIE2
strIE2 = ""
strIE2 = strIE2 & "<span class='xx'>XX</span>"
strIE2 = strIE2 & "<br>"
strIE2 = strIE2 & "<table border='1'>"
strIE2 = strIE2 & "<tr><th>TH</th></tr>"
strIE2 = strIE2 & "<tr><td>TD</td></tr>"
strIE2 = strIE2 & "<tr><td style='font-size:64pt'>TH</td></tr>"
strIE2 = strIE2 & "</table>"
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "about:blank"
While objIEA.Busy
Wend
objIEA.Visible = True
objIEA.Document.Title = "about_blank.htm"
objIEA.Document.Head.InnerHTML = strIE1
objIEA.Document.Body.InnerHTML = strIE2
Set objIEA = Nothing
[ I posted a variation of this over 5 hours ago but didn't see it in the
ng. ]
[snip]
Thanks for your reply.
Your solution does not work in my case.
I want to change declare a <style> section which should go in the <head>
section of a document created when building an "about:blank" page as below:
Option Explicit
Dim strIE1
strIE1 = ""
strIE1 = strIE1 & "<style type='text/css'>"
strIE1 = strIE1 & " td { font-size:64pt }"
strIE1 = strIE1 & " th { font-size:64pt; font-weight:bold }"
strIE1 = strIE1 & ".xx { font-size:64pt; font-weight:bold }"
strIE1 = strIE1 & "</style>"
Dim strIE2
strIE2 = ""
strIE2 = strIE2 & "<span class='xx'>XX</span>"
strIE2 = strIE2 & "<br>"
strIE2 = strIE2 & "<table border='1'>"
strIE2 = strIE2 & "<tr><th>TH</th></tr>"
strIE2 = strIE2 & "<tr><td>TD</td></tr>"
strIE2 = strIE2 & "<tr><td style='font-size:64pt'>TH</td></tr>"
strIE2 = strIE2 & "</table>"
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "about:blank"
While objIEA.Busy
Wend
objIEA.Visible = True
objIEA.Document.Title = "about_blank.htm"
''' objIEA.Document.{something} = strIE1
--
Joe
Thanks for your reply.
I'm trying to construct and display a Web page from within an HTA without
having to use FSO to write it out first.
"objIEA.document.write" is not a valid method for this.
P.S. I'd also like to be able to have the following work but they don't.
<span onclick="window.close">Close<span>
and
<span onclick="window.print">Print<span>
Perhaps I'll have to use FSO to do what I want after all....
I came up with a solution thanks to concepts at this link:
http://ourworld.compuserve.com/homepages/Guenter_Born/WSHBazaar/WSHInput1.ht
m
Option Explicit
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
objIEA.Navigate "about:blank"
While objIEA.Busy
Wend
Dim objIED
Set objIED = objIEA.Document
objIED.Open
objIED.Write "<hmtl>"
objIED.Write "<head>"
objIED.Write "<title>about-blank.vbs</title>"
objIED.Write "<style type='text/css'>"
objIED.Write " td { font-size:24pt }"
objIED.Write " th { font-size:24pt; font-weight:bold }"
objIED.Write ".xx { font-size:24pt; font-weight:bold }"
objIED.Write "</style>"
objIED.Write "<span class='xx'>XX</span>"
objIED.Write "</head>"
objIED.Write "<body>"
objIED.Write "<br>"
objIED.Write "<table border='1'>"
objIED.Write "<tr><th>TH</th></tr>"
objIED.Write "<tr><td>TD</td></tr>"
objIED.Write "</table>"
objIED.Write "<br>"
objIED.Write "<button onclick='window.close()'>Close</button>"
objIED.Write " "
objIED.Write "<button onclick='window.print()'>Print</button>"
objIED.Write "</body>"
objIED.Write "</hmtl>"
objIED.Close
Set objIED = Nothing
objIEA.Visible = True
Set objIEA = Nothing
1) Unfortunately, when I click "Close" I get a dialog asking:
"The Web page you are viewing is trying to close this window.
Do you want to close this window?
[Yes] [No]"
2) Also, I'd like to build a variable and write it; such as:
Dim strIED
strIED = "Hello World!"
objIED.Write strIED
But it returns an error.
Oh well, half a loaf ....
Please let me know if you have any additional ideas.
A variation of my last approach is:
Option Explicit
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
With objIEA
.Navigate "about:blank"
.Document.Open
.Document.Write "<hmtl>"
.Document.Write "<head>"
.Document.Write "<title>about-blank.vbs</title>"
.Document.Write "<style type='text/css'>"
.Document.Write " td { font-size:24pt }"
.Document.Write " th { font-size:24pt; font-weight:bold }"
.Document.Write ".xx { font-size:24pt; font-weight:bold }"
.Document.Write "</style>"
.Document.Write "<span class='xx'>XX</span>"
.Document.Write "</head>"
.Document.Write "<body>"
.Document.Write "<br>"
.Document.Write "<table border='1'>"
.Document.Write "<tr><th>TH</th></tr>"
.Document.Write "<tr><td>TD</td></tr>"
.Document.Write "</table>"
.Document.Write "<br>"
.Document.Write "<button onclick='window.close()'>Close</button>
"
.Document.Write "<button onclick='window.print()'>Print</button>
"
.Document.Write "</body>"
.Document.Write "</hmtl>"
.Document.Close
.Visible = True
End With
While objIEA.Busy
Wend
Set objIEA = Nothing
Though I still don't understand why the following doesn't work:
Dim strIEA
strIEA = "<i>Hello World!</i>"
.Document.Write strIEA
This link suggests that it should work:
http://www.mcse.ms/archive127-2004-1-347542.html
as it uses ".document.Write vHTMLBody".
(I guess it's different when used in a VB macro.)
Document.write is part of the DOM, as opposed to
TextStream.write, which does require FSO. Document
is a property of the window object. There's no reason
that the above shouldn't work except that the period
creates an undefined object reference. It looks like you're
missing a With/End With that was originally with that sample.
You can use something like:
window.document.write "blah"
OR
With window.document
.write "blah"
.write "more blah"
End With
Thanks for your reply.
I hoped that that statement would be read in context of the entire post;
that is, it does not work after inserting it into the script.
Here's a stripped down version that doesn't work:
<html>
<head>
<title>Hello.hta</title>
</head>
<body>
<script type="text/vbscript">
Option Explicit
Dim strIEA
strIEA = "<br>Hello World?"
Dim objIEA
Set objIEA = CreateObject("InternetExplorer.Application")
With objIEA
.Navigate "about:blank"
.Document.Open
.Document.Write "<hmtl><head>"
.Document.Write "<title>Hello World!</title>"
.Document.Write "</head><body>"
.Document.Write "Hello World!"
'* The following line does not work:
.Document.Write strIEA
.Document.Write "</body></hmtl>"
.Document.Close
.Visible = True
End With
While objIEA.Busy
Wend
Set objIEA = Nothing
</script>
</body>
</html>
It also doesn't work as a VBS file; that is, just the script portion, unless
the one line is commented out.
I don't know if I've ever tried to create an IE instance from
within a webpage, so I'm not sure whether there are any issues
with that. Is there any reason not to just use window.open?
Dim Win1, s
s = "hello world"
Set Win1 = window.open("", null,
"height=400,width=400,status=no,toolbar=yes, etc...")
With Win1.document
.Write "first line"
.Write "second line"
.Write s
.close
End With
That does the same thing except that you have limited access
to the actual IE object once the window is created. The 3rd
parameter takes numerous IE properties when setting up the
window, but what's returned in Win1 is a window object rather
than an IE object.
--
--
McKirahan <Ne...@McKirahan.com> wrote in message
news:nLGXc.324135$%_6.209652@attbi_s01...
[snip]
Thanks for the suggestion.
Though I couldn't get the example that I posted to work (perhaps it's a
timing issue as you suggested; I'll try again), I did get it (writing a
variable) to work in my production code.
> "mayayana" <mayaXX...@mindYYspring.com> wrote in message
> news:mNPXc.729$JT3...@newsread3.news.atl.earthlink.net...
[Trouble with a VBScript-String passed from HTA to
IE-document.write]
> Though I couldn't get the example that I posted to work (perhaps it's a
> timing issue as you suggested; I'll try again), I did get it (writing a
> variable) to work in my production code.
I could repro your problem, the error says that a Variant-Type is used
that isn't supported by VBScript/or a NULL-Poniter was passed to the stub.
So somehow that string is stored by VBScript in a variant-subtype
that document.write can't handle.
Work-around: same script in JScript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-16">
<title>Hello.hta</title></head><body>
<script type="text/jscript">
var objIEA = new ActiveXObject("InternetExplorer.Application");
var s = "<br>Hello World?";
with (objIEA) {
Navigate ("about:blank");
while (Busy);
Document.open();
Document.write ("<hmtl><head>");
Document.write ("<title>Hello World!</title>");
Document.write ("</head><body>");
Document.write ("Hello World!");
//* The following line does work now:
Document.write (s);
Document.write ("</body></hmtl>");
Document.close();
Visible = true ;
}
</script>
</body>
</html>
--
HAND, Christoph
Rio Riay Riayo - Gordon Sumner, 1979
The solution is ByVal.
If you want to make your script work in VBScript, you must pass
the String *ByValue*. (that's why it works in JScript, which
doesn't know ByRef).
You have to wrap it into round brackets to do so.
Obviously a string cannot be passed ByRef between *two* processes
in VBScript, maybe because you cannot be sure, what kind of
datatype is returned from the other process, and if it is
automation-compatible.
<head><title>Hello.hta</title>
</head><body><script type="text/vbscript">
Option Explicit
Dim strIEA, objIEA
strIEA = "<br>Hello World?"
Set objIEA = CreateObject("InternetExplorer.Application")
With objIEA
.Navigate "about:blank"
.Document.Open
.Document.Write "<hmtl><head>"
.Document.Write "<title>Hello World!</title>"
.Document.Write "</head><body>"
'wrap the string into round brackets, then it's passed *ByVal*
.Document.Write (strIEA)
.Document.Write "</body></hmtl>"
.Document.Close
.Visible = True
End With
</script></body></html>
If you use roughly the same code, to write to the *same* document
then it's know problem to pass the string ByRef, because there
is not process-boundary to be crossed and no
proxy/stub to be created.
<html><head><title>Hello.hta</title></head><body>
<script type="text/vbscript">
Option Explicit
Dim str
str = "<br>Hello World?"
document.Open
document.Write "<hmtl><head>"
document.Write "<title>Hello World!</title>"
document.Write "</head><body>"
document.Write "Hello World!"
document.Write str 'ByRef works here!
document.Write "</body></hmtl>"
document.Close
</script>
</body>
</html>
--
Gruesse, Christoph
Excellent! Thanks, I didn't know that.