Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Excel object from vbscript frontend function 1

Status
Not open for further replies.

DKL01

Programmer
Sep 14, 2000
233
US
Hi,

Is it possible to create Excel object from frontend vbscript function ? I tried following code. But it gives error.

<html>
<body>

<input type=&quot;button&quot; value=&quot;View result in Excel&quot; name=&quot;btnExcel&quot;>

<script language=&quot;vbscript&quot;>
sub btnExcel_onclick()
dim xlApp
Set xlApp = CreateObject(&quot;Excel.Application&quot;)
end sub
</script>


</body>
</html>

Thanks
[sig][/sig]
 
You almost got it right. Use the following bit of code as a starting point...

Code:
<html>
 <head>
  <script language=&quot;vbscript&quot;>
   Sub btnExcel_onclick()
    dim objXL
    Set objXL = CreateObject(&quot;Excel.Application&quot;)
    objXL.Visible = TRUE
    objXL.WorkBooks.Add

    objXL.Columns(1).ColumnWidth = 25
    objXL.Columns(2).ColumnWidth = 25
    objXL.Columns(3).ColumnWidth = 30
    
    objXL.Rows(&quot;1:1&quot;).Select
    objXL.Selection.Font.Bold = True
    
    objXL.Range(&quot;C2:C2&quot;).Select
    objXL.Selection.Font.Bold = True
    objXL.Selection.Font.Underline = True
    objXL.Selection.Interior.ColorIndex = 27 'Yellow
    objXL.Selection.Interior.Pattern = 1 'Solid

    objXL.Cells(1, 1).Value = &quot;Divisee&quot;
    objXL.Cells(1, 2).Value = &quot;Divisor&quot;
    objXL.Cells(1, 3).Value = &quot;Results&quot;
    objXL.Cells(2, 1).Value = 3898723982
    objXL.Cells(2, 2).Value = 38374
    objXL.Cells(2, 3).Value = &quot;=SUM(A2/B2)&quot;
   End Sub
</script>
<body>
 <input type=&quot;button&quot; value=&quot;View result in Excel&quot; name=&quot;btnExcel&quot;>
</body>
</html>

Hope it helps, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
Rob,

I'm getting error
ActiveX component can't create object 'Excel.Application'

Thanks
Dilip [sig][/sig]
 
Make sure HKEY_CLASSES_ROOT\Excel.Application (this is the COM object) exists in the registry. There should be a CLSID that points to a HKCR\clsid key that should have a LocalServer32 Default value that points to your Excel installation. If all that is OK you may need to install the latest WSH scripting engine ( though I doubt that would help. Perhaps the latest MDAC (2.5 sp1) or (if on 9x) the latest DCOM. I'm using Win2K SP1 with IE 5.5 and Office 2000 SR1 so other combinations aren't immediately tested.

Later, [sig]<p>Rob<br><a href=mailto:robschultz@yahoo.com>robschultz@yahoo.com</a><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
"Focus on the solution to the problem,<br>
not the obstacles in the way."<br>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[/sig]
 
If you write it in as a ASP page you need to write it as
Server.CreateObject(&quot;Excel.Application&quot;)
and If you write it in note pad and run it under windows scripting host the code looks like this CreateObject(&quot;Excel.Application&quot;)

Wayne
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top