Strange Automation Behaviour - Excel

  • Thread starter Thread starter Arturo
  • Start date Start date
A

Arturo

Hello everybody. Can someone have a look at this bit of code?

Private Sub TestExcel()
'Create the Excel Application
Dim xlExcel As Application = New Excel.Application
xlExcel.DisplayAlerts = False

Dim xlWorkbooks As Workbooks = xlExcel.Workbooks

Try
Dim xlWorkbook As Workbook = xlWorkbooks.Open("D:\Test.xls")
Try
Dim xlWorksheets As Sheets = CType(xlWorkbook.Worksheets,
Sheets)
Dim xlWorksheet As Worksheet

For Each xlWorksheet In xlWorksheets
xlWorksheet = Nothing
Next
xlWorksheets = Nothing
Finally
xlWorkbook.Close()
xlWorkbook = Nothing
End Try
Finally
xlWorkbooks = Nothing
xlExcel.Quit()
xlExcel = Nothing
GC.Collect()
End Try
End Sub

....You will get an error from excel saying "Memory could not be read".
If you change the "For Each" and put a standard For iX = 1 To
xlWorksheets.Count the problem goes away. Any explanation? I think
is the way For Each gets the enumerator, but I don't know. I need to
use automation a lot, and I would like to know what is the real
behaviuor of excel in this case.

Thanks a lot.

Arturo
 
Hi Arturo,

There is a known issue with using "For each" for Excel collections. Check out
the article below.

328347 PRB: "Member Not Found" Error Message When You Use a For Each Statement
http://support.microsoft.com/?id=328347

The work around is the same as you have mentioned. The error seems to be the
different in your case but it may be dependent on the version of Excel or if
you have installed PIA or not.


Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Thanks, Bharat. I supposed was a bug. Thanks for the information. I
have another question, and I don't know if you can help me. Is
regarding Licensing and custom LicenseProviders in dotnet.

I followed the instructions inthe documentation and I've gone through
the document in gotdotnet, and everything works fine, except for one
thing.

I am using DataDynamics ActiveReports, and apparently this is a
Licensed component. The issue is that my licensing scheme gets in
conflict with activereports and I don't understand how this can be.

(My classes as registered with the
<LicenseProvider(GetType(MyCustomLicenseProvider))> _ attribute)

Thanks!

Arturo
 
Arturo,

Can you explain what kind of conflicts do you see?
What happens and what error messages you get? Also what kind of LicenseProvider
you are using?

Thanks!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
I sorted it, although I don't really know what was exactly happening.
What I was doing was


Sub Main()

...
...
LicenseManager.CurrentContext = New CustomLicenseContext(..mydata..)
...
...
End Sub

And apparently, CurrentContext loads licenses.licx at startup (or if
it is null, loads licenses.licx. That's the only explanation I can
find.) What strikes me is that if you have different licensing
schemes from different vendors, How can you manage to use them
together? Maybe I am doing something wrong. Where can I find
detailed technical information? Is sorted by now, but It would be
nice to understand licensing in .NET (i've found too litle information
in msdn regarding to this)

On the other hand, I have problems with DateTimePickers. Something
similar to this.

http://groups.google.com/groups?hl=...ty&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search

I haven't manage to reproduce the problem in an isolated solution. I
think is a bug with the framework wrapper of the windows control...

Thanks for your help. See you.
 
Back
Top