¤ Hello World,
¤
¤ I've found a problem regarding Interop on Excel 2000.
¤
¤ Here's KB article where the problem should be discussed:
¤ http://support.microsoft.com/default.aspx?scid=kb;EN-US;317109
¤
¤ After Applying KB arrticle Still Excel won't quit after subroutine if.
¤
¤ oSheet.Copy(oSheet, )
¤
¤ function is executed.
¤
¤ If I omit the above line from the code everything works fine... any
¤ ideas?
¤ I've read that OXPPIAs have been tested under framework 1.0 and I'm
¤ actually using visual studio 2003 but I cant' revert my project to
¤ 2002...
¤
¤ Reproducting behaviour code follows...
¤
¤ Thanks,
¤ Claudio
¤ ------------------------------------
¤ Dim oExcel As Object
¤ Dim oBook As Object
¤ Dim oWbs As Object
¤ Dim oWb As Object
¤ Dim oSheets As Object
¤ Dim oSheet As Object
¤
¤ oExcel = CreateObject("Excel.Application")
¤ oExcel.visible = True
¤ System.Threading.Thread.CurrentThread.Sleep(3000)
¤ oWbs = oExcel.Workbooks
¤ oWb =
¤ oWbs.Open("C:\Bonghi\Ddm\LagDuf\JSR\jsr_dot_net\LD_JSR\Reports\store\1.xls")
¤ oSheets = oWb.sheets
¤ oSheet = oSheets(1)
¤ oSheet.Copy(oSheet, ) ' <--- This line causes Excel task not to quit
¤ oWb.Save()
¤
¤ ' NAR sub Taken from KB Article
¤ '
¤ NAR(oSheet)
¤ NAR(oSheets)
¤ NAR(oWb)
¤ NAR(oWbs)
¤ oExcel.quit()
¤ NAR(oExcel)
¤
¤
¤ GC.Collect()
The Copy method call is probably creating an implicit (Worksheet) object reference. Try setting an
object variable to the Copy statement and then use NAR function to destroy that object.
oWorksheet = oSheet.Copy(oSheet, )
'...
NAR(oWorksheet)
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
Claudio Benghi - 22 Nov 2003 23:18 GMT
>The Copy method call is probably creating an implicit (Worksheet) object reference. Try setting an
>object variable to the Copy statement and then use NAR function to destroy that object.
[quoted text clipped - 7 lines]
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
Excuse me for answeing this late... I've had some (other) troubles...
Anyway... the copy function just returns a bool.
I suppose it's just success or not.
Any other Idea?
Many thanks for your reply.
Claudio
Paul Clement - 24 Nov 2003 16:44 GMT
¤ On Thu, 20 Nov 2003 09:59:12 -0600, Paul Clement
¤ <UseAdddressAtEndofMessage@swspectrum.com> wrote:
¤ >
¤ >The Copy method call is probably creating an implicit (Worksheet) object reference. Try setting an
¤ >object variable to the Copy statement and then use NAR function to destroy that object.
¤ >
¤ >oWorksheet = oSheet.Copy(oSheet, )
¤ >
¤ >'...
¤ >
¤ >NAR(oWorksheet)
¤ >
¤ >
¤ >Paul ~~~ pclement@ameritech.net
¤ >Microsoft MVP (Visual Basic)
¤
¤ Excuse me for answeing this late... I've had some (other) troubles...
¤
¤ Anyway... the copy function just returns a bool.
¤
¤ I suppose it's just success or not.
¤
¤ Any other Idea?
¤
¤ Many thanks for your reply.
¤
¤ Claudio
It looks to me as if Excel eventually terminates once you close the application. If you need to
repeatedly use Excel automation while the application is running you may want to use GetObject to
return a currently running instance.
Since it appears that Excel is creating an implicit object reference for the new (copied) worksheet
I don't see any way to get at it. For whatever reason the Copy method doesn't return a object
reference, which is contrary to the Excel documentation.
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)