ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error about ExcelApp.Workbooks.Add (https://www.excelbanter.com/excel-programming/275035-re-error-about-excelapp-workbooks-add.html)

YaYa[_2_]

Error about ExcelApp.Workbooks.Add
 
Hello, It still has the problem.

When I open this created Excel file, then:
If I press right-up corner inner X button(This Excel File) === has a
problem.
If I press File - Digest Information === has a problem.
If I press right-up corner outer X button(Excel Application) === No
problem.
If I press File - Close File === No problem.
If I press File - Exit === No problem.
(P.S.: Running this web page and opening this Excel file are on the same
computer.)

If opening this Excel file on other computer, it doesn't have any problems.

How to solve it?
Thanks.

This is the code(web page):
It runs on .Net Framework 1.1.
----------------------------------------------------------------------------
-
<%@ Page Language="vb" debug="true" %
<%@ import Namespace="Excel" %
<html
<body
<%
Dim xlApp As Excel.Application
xlApp = New Excel.Application()

Dim xlWk As Excel.Workbook
Dim xlRg As Excel.Range

Try
xlWk = xlApp.Workbooks.Add()

xlRg = xlWk.Worksheets(1).Range("A1")
xlRg.Value = "whatever data I want"

Dim blah as String
blah = "C:\Inetpub\temp\Books.xls"
xlWk.SaveAs(blah)

xlWk.Close()
Catch e As System.Runtime.InteropServices.COMException
Response.Write(e)
End Try

xlApp.Workbooks.Close()
xlApp.DisplayAlerts=False
xlApp.Quit()
xlRg = Nothing
xlWk = Nothing
xlApp = Nothing
%
</body
</html
----------------------------------------------------------------------------
-



"Keith Willshaw" ¼¶¼g©ó¶l¥ó·s»D
...

"YaYa" wrote in message
...
Thanks.

It can create a Excel file now.

But, if I open this created Excel file, then close this Excel file,
System will show a window:
Microsoft Excel occurs problems, it must be closed, sorry.
It has three buttons: Debug, Reply this problem, and Not reply.
(P.S.: This is I translate strings from Chinese words.)

Do you have this problem?
And Why? How to solve?

Thanks.


You need to release all objects and close the Excel instance
before ending

Typically

xlApp.DisplayAlerts=False
xlApp.Quit

Set xlWk=Nothing
Set xlApp=Nothing

Keith





Keith Willshaw

Error about ExcelApp.Workbooks.Add
 

"YaYa" wrote in message
...
Hello, It still has the problem.

When I open this created Excel file, then:
If I press right-up corner inner X button(This Excel File) === has a
problem.


What is the problem ?

If I press File - Digest Information === has a problem.


What is the problem ?


If I press right-up corner outer X button(Excel Application) === No
problem.
If I press File - Close File === No problem.
If I press File - Exit === No problem.
(P.S.: Running this web page and opening this Excel file are on the same
computer.)

If opening this Excel file on other computer, it doesn't have any

problems.

How to solve it?
Thanks.

This is the code(web page):
It runs on .Net Framework 1.1.
--------------------------------------------------------------------------

--
-
<%@ Page Language="vb" debug="true" %
<%@ import Namespace="Excel" %
<html
<body
<%
Dim xlApp As Excel.Application
xlApp = New Excel.Application()

Dim xlWk As Excel.Workbook
Dim xlRg As Excel.Range

Try
xlWk = xlApp.Workbooks.Add()

xlRg = xlWk.Worksheets(1).Range("A1")
xlRg.Value = "whatever data I want"

Dim blah as String
blah = "C:\Inetpub\temp\Books.xls"
xlWk.SaveAs(blah)

xlWk.Close()
Catch e As System.Runtime.InteropServices.COMException
Response.Write(e)
End Try

xlApp.Workbooks.Close()


I suggest replacing this with a statement explicitly
closing the workbook yo manipulated

xlWk.Close

Keith




All times are GMT +1. The time now is 03:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com