473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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(ClassName, "Microsoft Excel - ROI_" &
Request.QueryString("ROIHeaderID") & "_" & CStr(XLNumbers) & ".xls")
If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, WM_QUIT, 0, 0)
End If
Next

WindowHandle = FindWindow(ClassName, "Microsoft Excel - ROI_" &
Request.QueryString("ROIHeaderID") & "_ALL.xls")
If WindowHandle Then
ReturnVal = PostMessage(WindowHandle, 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("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cim v2")
'Connect to CIMV2 Namespace

Dim objList = objWMIcimv2.ExecQuery _
("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.Terminate '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.Application
Dim xlSheet As Excel.Worksheet

xlAppl = New Excel.Application
xlAppl.Workbooks.Open(strFileName)
xlAppl.Workbooks(1).Activate()

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

*** code fills in some values

xlAppl.Workbooks(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 1360

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

Similar topics

2
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...
0
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...
4
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...
6
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 ...
1
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...
3
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...
1
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...
2
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 .......
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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,...

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.