ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   closing an excel worksheet inside vb .net (https://www.excelbanter.com/excel-programming/281775-closing-excel-worksheet-inside-vbulletin-net.html)

Bernie Yaeger

closing an excel worksheet inside vb .net
 
I have the following code fragment for opening and the closing excel in a vb
..net app:
objxl = New Excel.Application

objwbs = objxl.Workbooks

objwb = objwbs.Add

objws = CType(objwb.Worksheets(1), Excel.Worksheet)



objwb.SaveAs(strpath, xlCSV)

objxl.DisplayAlerts = False

'objws.close()

objxl.DisplayAlerts = True

Marshal.ReleaseComObject(objws)

objxl.Quit()

My question is, how do you close opjws? The close method no longer exists.

Tx for any help.

Bernie




Rob Bovey

closing an excel worksheet inside vb .net
 
Hi Bernie,

A Worksheet object doesn't have a close method. It's the objwb variable,
which represents an Excel.Workbook object, that you need to close. If the
objws variable is a local variable, you really don't need to do anything at
all, but if you want to explicitly release it for garbage collection then
add the following line to your code:

objws = Nothing

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Bernie Yaeger" wrote in message
...
I have the following code fragment for opening and the closing excel in a

vb
.net app:
objxl = New Excel.Application

objwbs = objxl.Workbooks

objwb = objwbs.Add

objws = CType(objwb.Worksheets(1), Excel.Worksheet)



objwb.SaveAs(strpath, xlCSV)

objxl.DisplayAlerts = False

'objws.close()

objxl.DisplayAlerts = True

Marshal.ReleaseComObject(objws)

objxl.Quit()

My question is, how do you close opjws? The close method no longer

exists.

Tx for any help.

Bernie






onedaywhen

closing an excel worksheet inside vb .net
 
How do you close a worksheet manually?! I don't think you need to
close/release the worksheet object in your code because you are only
setting a reference/pointer to it.

"Bernie Yaeger" wrote in message t...
I have the following code fragment for opening and the closing excel in a vb
.net app:
objxl = New Excel.Application

objwbs = objxl.Workbooks

objwb = objwbs.Add

objws = CType(objwb.Worksheets(1), Excel.Worksheet)



objwb.SaveAs(strpath, xlCSV)

objxl.DisplayAlerts = False

'objws.close()

objxl.DisplayAlerts = True

Marshal.ReleaseComObject(objws)

objxl.Quit()

My question is, how do you close opjws? The close method no longer exists.

Tx for any help.

Bernie


Bernie Yaeger

closing an excel worksheet inside vb .net
 
Hi Rob,

Thanks so much - not closing objwb was indeed my problem.
Tx again,
Bernie
"Rob Bovey" wrote in message
...
Hi Bernie,

A Worksheet object doesn't have a close method. It's the objwb

variable,
which represents an Excel.Workbook object, that you need to close. If the
objws variable is a local variable, you really don't need to do anything

at
all, but if you want to explicitly release it for garbage collection then
add the following line to your code:

objws = Nothing

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Bernie Yaeger" wrote in message
...
I have the following code fragment for opening and the closing excel in

a
vb
.net app:
objxl = New Excel.Application

objwbs = objxl.Workbooks

objwb = objwbs.Add

objws = CType(objwb.Worksheets(1), Excel.Worksheet)



objwb.SaveAs(strpath, xlCSV)

objxl.DisplayAlerts = False

'objws.close()

objxl.DisplayAlerts = True

Marshal.ReleaseComObject(objws)

objxl.Quit()

My question is, how do you close opjws? The close method no longer

exists.

Tx for any help.

Bernie









All times are GMT +1. The time now is 02:04 AM.

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