RE: integrating vbscript into a web page by JimRodgers
JimRodgers
Sat Aug 05 15:31:02 CDT 2006
If I understand what you are saying, you are trying to use ASP's VBScript on
the IIS server side to embed a VBScript in the HTML for the client browser to
run.
You do it one of two ways like this:
First Method -- Just write it directly into the HTML part of the .asp file:
There are no <% or %> tags. You don't even use the VBScript on the IIS
Server side.
<HTML>
<BODY>
<H1>Hello World!</H1>
<SCRIPT LANGUAGE="VBScript">
msgbox "Now you are cooking!"
</SCRIPT>
/<BODY>
</HTML>
Second Method -- create a script from within VBScript on the IIS to
"Response.Write" to the HTML stream going to the browser. Here I also show
you how to take a value from within the ASP VBScript and plant it into the
Browser VBScript -- and save it as an Excel file on the client PC while
you're at it!
<HTML>
<BODY>
<H1>Hello World!</H1>
<%
'
strText = "Server has something to say!"
'
Response.Write "<SCRIPT LANGUAGE=""VBScript"">" & vbCrLf
Response.Write " dim app" & vbCrLf
Response.Write " set app = createobject(""Excel.Application"")" & vbCrLf
Response.Write " app.Visible = False" & vbCrLf
Response.Write " app.DisplayAlerts = False" & vbCrLf
Response.Write " dim wb" & vbCrLf
Response.Write " set wb = app.Workbooks.Open(""C:\MyExcelFile.xls"")" & vbCrLf
Response.Write " wb.Worksheets(""Sheet1"").Activate" & vbCrLf
Response.Write " wb.Activesheet.Range(""A1"").Formula = """ & strText & """"
& vbCrLf
Response.Write " wb.SaveCopyAs ""C:\MyOtherExcelFile.xls""" & vbCrLf
Response.Write " wb.Close False ' Close " & vbCrLf
Response.Write " app.Quit ' Quit the hidden Excel app instance." & vbCrLf
Response.Write "'End Sub" & vbCrLf
Response.Write "</SCRIPT>" & vbCrLf
'
%>
/<BODY>
</HTML>
Pretty cool, eh? Remember, if you don't need a lot of program control on
the ASP side to generate the script, use Method #1. I use Method #2 when I
need to retrieve a recordset on the server and then embed the data into a
spreadsheet or something like that. You can use the Macro Recorder in Excel,
Word, etc., to "learn" the 98% correct VB commands to use when manipulating
MS Office files in a VBScript. Oh yeah, don't bother trying to use Excel or
Word on the server side. It's really hard. Even on the client side, you
have to put the server URL in the "Trusted Group" if the VBScript has to
"talk" to Excel, etc. For simple scripts, of course, no special anything is
required.
And try to avoid using VBScript on the browser unless you really have to.
Use JScript instead. You may as well learn it because javascript is what
they use in DHTML (Dynamic HTML).
Cheers, dude,
Jim R.
--
James W. (Jim) Rodgers, P.E., is a Senior Partner with General Consulting
Engineers, LLC, in Atlanta, Georgia.
"CitizenMundane" wrote:
> Trying to add a vbscript to a web page, so that users don't have to click
> "save" or "download"...
> Running IIS 5.0
> tried saving the page as an .asp file, enclosing the code in
> <%
> %>
> tried creating the code in an .hta file, with
> <Script Language ="VBScript">
> code
> </Script>
>
> Someone suggested I start the IIS services with a domain account, but that
> didn't work either....
>
> Any suggestions are welcome...
> Thanks
>
>
>