473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strange Automation Behaviour - Excel

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
Nov 20 '05 #1
4 1125
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.

Nov 20 '05 #2
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
Nov 20 '05 #3
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.

Nov 20 '05 #4
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=e...oogle%2BSearch

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.
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jimmer | last post by:
I've got what should be an easy automation problem, but the solution simply isn't coming to me. I've got several public variables set up for automation as follows: Public gappExcel As...
7
by: taylor.bryant | last post by:
I am running: Win XP SP2 Excel 2002, Access 2002 (Office XP SP3) Using Visual Basic (not VB.NET) At one point (prior to XP SP2?!? - I can't pin it down), this did not happen and I was easily...
1
by: cybertof | last post by:
Hello, Is there a way to connect (through automation) a c# application to a running Excel 2003 instance on a specific workbook ? In the past, i used to use GetObject(...) function in VB6. ...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
3
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
3
by: Mitchell Vincent | last post by:
Does anyone have some good examples of Excel automation with (VB).NET? I have some Excel spreadsheets that a customer needs parsed out but I've never tried to use Excel programatically before! ...
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
0
by: Piotr Kosinski | last post by:
Hi, I noticed strange behaviour in Excel. I wrote small shared add in for Excel. This util create button in standard bar. Button click provides to open a form which has to import data from sql...
0
by: xrxst32 | last post by:
Hello there, I have some doubts about the best practice for using COM automation, the Runtime Callable Wrapper (RCW) and Marshal.ReleaseComObject. So the question is/are: Do I need to release...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.