Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default 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





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing workbooks w/o closing Excel Barb in MD Excel Discussion (Misc queries) 3 February 15th 10 06:42 PM
turning a worksheet inside out Don Excel Discussion (Misc queries) 8 March 11th 08 10:32 PM
closing a 2007 worksheet Suzi-Q Excel Discussion (Misc queries) 4 February 12th 08 01:35 AM
Excel Crashes after Inserting New Worksheet and Closing the File ttt Excel Discussion (Misc queries) 4 November 16th 05 01:38 PM
Tabs Inside of a worksheet havocdragon Excel Worksheet Functions 2 November 24th 04 09:19 PM


All times are GMT +1. The time now is 11:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"