473,591 Members | 2,871 Online
Bytes | Software Development & Data Engineering Community
+ 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.Applicati on
xlExcel.Display Alerts = False

Dim xlWorkbooks As Workbooks = xlExcel.Workboo ks

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

For Each xlWorksheet In xlWorksheets
xlWorksheet = Nothing
Next
xlWorksheets = Nothing
Finally
xlWorkbook.Clos e()
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.Co unt 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 1134
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 LicenseProvider s 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
<LicenseProvide r(GetType(MyCus tomLicenseProvi der))> _ 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 CustomLicenseCo ntext(..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
808
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 Excel.Application 'ADO Object for Excel Automation Public gstrExcelDir As String 'Source or Destination Directory
7
5332
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 able to destroy instances of excel (with the exact same code). I have read many, many posts, and they seem to get bogged down in specifics. So I cribbed this program from the automation help file, simplified it further, so hopefully someone can
1
5040
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. Regarding C#, I have heard about System.Runtime.InteropServices.marshal.GetActiveObject ("Excel.Application")
17
6326
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
2797
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 value into a cell. BUT this is where it comes "complex".
3
2179
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! Thanks! -- - Mitchell Vincent - kBilling - Invoices Made Easy!
6
598
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 Excel.Range
0
1105
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 server and present on listbox, double click date should be paste into activecell in excel. Because shared add in is loaded with excel i use: myexcel = getobject(, "excel.application")
0
2725
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 each COM object explicit by a call to Marshal.ReleaseComObject, does the RCW take care of that or does it leaks unmanaged resources?
0
7934
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7870
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8225
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5732
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3850
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.