473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VS2005 vb.net DLL - interop EXCEL

Hello All

I am working a on web application created in Visual Studio 2005 VB.
It has to do some work with Excel files, so I created a DLL in VS2005.

My development machine is XP SP3.
When my web app runs it opens a few excel files and fills certain locations
and then the excel spreadsheet is calculated.
(there are many calculations)

To ensure I was closing only the files I had opened during this process I
use code like this:

Dim ClassName As String = "XLMain"
Dim XLNumbers As Int16
Dim WindowHandle As Int32
Dim ReturnVal As Int32
Const WM_QUIT = &H12

For XLNumbers = 12 To 17
WindowHandle = FindWindow(Clas sName, "Microsoft Excel - ROI_" &
Request.QuerySt ring("ROIHeader ID") & "_" & CStr(XLNumbers) & ".xls")
If WindowHandle Then
ReturnVal = PostMessage(Win dowHandle, WM_QUIT, 0, 0)
End If
Next

WindowHandle = FindWindow(Clas sName, "Microsoft Excel - ROI_" &
Request.QuerySt ring("ROIHeader ID") & "_ALL.xls")
If WindowHandle Then
ReturnVal = PostMessage(Win dowHandle, WM_QUIT, 0, 0)
End If

This works perfectly on my development machine.

The deployment machine is Windows Server 2003.
None of the excel files close using the code above. The only thing that
works there is using something like this:

' check for any EXCEL processes that stuck
Dim objWMIcimv2 = GetObject("winm gmts:" _
& "{impersonation Level=impersona te}!\\.\root\ci mv2")
'Connect to CIMV2 Namespace

Dim objList = objWMIcimv2.Exe cQuery _
("select * from win32_process where name='EXCEL.EXE '") 'Find the
process to terminate

Dim objProcess As Object
Dim intRslt As Int16
For Each objProcess In objList
intRslt = objProcess.Term inate 'Terminates a process and all of
its threads.
Next

Now while this removes the excel files in memory, it removes ALL of them.
As this is meant to work with a web site and more then 1 (but maybe 5 total
concurrent users) person may be using the site, this isn't a viable
solution.

The files are opened like this:
(there is a reference to excel in the DLL project)

Dim xlAppl As Excel.Applicati on
Dim xlSheet As Excel.Worksheet

xlAppl = New Excel.Applicati on
xlAppl.Workbook s.Open(strFileN ame)
xlAppl.Workbook s(1).Activate()

strSheetName = "Input Sheet"
xlSheet = xlAppl.Sheets(s trSheetName)

*** code fills in some values

xlAppl.Workbook s(1).Save()
xlAppl.Quit()

xlAppl = Nothing

Some files are left open using this code, which lead me to find something
that allows me to clean up after this.

Is it possible to target process that have certain file names open and shut
them down, in windows server 2003?
Maybe it would just be better for the web app to fill a queue of excel files
that need processing .. and have a desktop application running under a
username?
(though they really require feed back of the changes the new calculations
made .. which are saved to a database)

Any ideas about getting excel to actually close when its asked to?

Thanks

Jul 18 '08 #1
0 1372

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

Similar topics

2
1011
by: Le Thanh Thuan | last post by:
In my VB.Net project, I using Interop.Excel 11.0 (Excel 2003 I create Setup project in my computer, and then , I setup in another computer using Excel 2000 When I run my application, a error occur File or assembly name Interop.Excel, or one of its dependencies, was not found. File name"Interop.Excel"
0
2642
by: Don Stevic | last post by:
I am running VS2005 and using VSTO for Word. I keep getting this error saying that there is no source code available for this location when I try and run this application. I am going to try and reinstall Office 2003 and see if that fixes this, but it is talking about the mscorlib.dll and that isn’t Office.
4
8098
by: Robert | last post by:
I have created a .dll in C# which has a reference to Excel. When I add a strong name to the .dll in the AssemblyInfo.cs and try to rebuild, I get the following error: Assembly generation failed -- Referenced assembly 'Interop.Excel' does not have a strong name How can this be resolved? -- Robert Hill
6
1174
by: Vayse | last post by:
I removed the Beta 2, and installed VS2005 Release Candidate. However, now have a bug where tables are not visbile in the data sources window. I checked on the MS site, and its bug ID FDBK37411 The fix there is to remove everything VS related and install again. I used the MS uninstall tool. I've done that and I still have the same problem....
1
1581
by: Rick | last post by:
Hi guys, i made an app using C# (vs2005) and i added some references to MS Excel in my project, when i try to install the app in a machine it begins but at some time it says "Cant find file My_App_Name.application" (that file exist at the directory when im publishing the installer), the closes itself, but i can execute my app because there are...
3
5106
by: Brent | last post by:
I'm trying to open and manipulate an Excel spreadsheet from C#. To that end, I've referenced Interop.EXCEL9.dll, which I have on my machine. All of the examples I've read say to do something like this: -------------------------- Excel.Application xl = new Excel.ApplicationClass(); xl.Visible = "true"; String workbookPath =...
1
1930
by: Geoff | last post by:
Hello I am having an issue with my code below not closing EXCEL.EXE when I tell it do. Any help would be appreciated. ----- Dim excel As Microsoft.Office.Interop.Excel.Application Dim wb As Microsoft.Office.Interop.Excel.Workbook Dim ws As Microsoft.Office.Interop.Excel.Worksheet
2
8329
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .... webOCWraooer,Copy // get the desired data into clapboard
5
1898
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I've been tasked to translate a C# program to VB. (Dot Net 2.0.) I'm starting from scratch with no documentation and I'm trying to understand what the original programmer did. (The 'original programmer' is conveniently off on vacation so I can't ask him.) The program deals in some way with Excel spreadsheets. There is a line of code in...
0
7468
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...
0
7401
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...
0
7656
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. ...
0
7808
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...
0
7757
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...
1
5329
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
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.