473,788 Members | 2,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting existing Excel instance the .Net way?

In VB6, I would check to see if Excel was already running by this technique

Private m_booExcelCreat edHere As Boolean

Dim xlApp as Excel.Applicati on

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Exc el.Application" )
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Applicati on
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreat edHere = True
Else
m_booExcelCreat edHere = False
End If

Later on, I'd use m_booExcelCreat edHere to determine if I should leave Excel
running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?
Nov 20 '05 #1
1 8378
Hi,

If Process.GetProc essesByName("ex cel").GetLength (0) > 0 Then

MessageBox.Show ("Excel is running")

Else

MessageBox.Show ("Not running")

End If

Ken

----------------------------

"Fred Morrison" <fm*******@erol s.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
In VB6, I would check to see if Excel was already running by this technique
Private m_booExcelCreat edHere As Boolean

Dim xlApp as Excel.Applicati on

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Exc el.Application" )
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Applicati on
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreat edHere = True
Else
m_booExcelCreat edHere = False
End If

Later on, I'd use m_booExcelCreat edHere to determine if I should leave Excel running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?

Nov 20 '05 #2

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

Similar topics

8
3372
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
2
10653
by: Anne Sachleben via AccessMonster.com | last post by:
I am using the TransferSpreadsheet function to export a query result to a specific worksheet in an Excel file titled "report". I want the result to be exported to the worksheet titled "facts". Here are the parameters I entered: Transfer Type: Export Spreadsheet Type: Microsoft Excel 8-10 Table Name: facts query File Name: C:\report.xls Has Field Names: No
2
1891
by: Adine | last post by:
User has opened an excel file and I want to take the control of the file. In VB6 was not hard. Just I needed to use "GetObject" then I could select the workbook. But now I don't know how to do it in C#. Thanks
4
3200
by: Josh Behl | last post by:
When I try to programmatically open an existing Excel document using a custom windows form, it works perfectly. I instanciate a new instance of the Excel.ApplicationClass and then set the Visible property to 'true'...then I open the workbook in question via my code..... However, when I try this using ASP.NET. It does not work. I've messed around and gave full access and control to my ASPNET user to practically every darn folder on...
2
2186
by: leeedw | last post by:
Hi everyone, I use the following code whenever I export to Excel from VB.NET objExcel = New Excel.Application() objWorkBooks = objExcel.Workbooks objWorkBook = objWorkBooks.Add objWorkSheet = objExcel.ActiveWorkbook.ActiveSheet The problem is that every time I need to export, it results in creating
3
3032
by: Ian Dunn | last post by:
I'm simply trying to access an instance of Excel that has been opened manually by the user in order to put a few values in the existing sheet. Here's the code I've tried: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet oXL = GetObject(, "Excel.Application") oWB = oXL.ActiveWorkbook oSheet = oWB.ActiveSheet
4
5846
by: Marco Aschwanden | last post by:
Hi I would like to 1. import an existing Excel-sheet (a template) 2. and add some data to it 3. and save it under a different name afterwards. To me it seems, that pyExcelerator does not support the reading for modification of an Excel-sheet. It allows only the "parse_xls" but I would like to keep the "formatting" in the template.
9
4550
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso TypeOf obj Is IDisposable Then DirectCast(obj, IDisposable).Dispose()
1
2756
by: popsoftheyear | last post by:
I'm trying to automate some very simple things in excel, but have run into a roadblock (using c++). To detect excel closing, I just monitor the Excel Process using WaitForSingleObject. In order to close it myself, I just call ExcelApp.Quit(). Really basic stuff. Only problem is - I need to release all dispatches to detect the Excel process closing, but I need those dispatches (at least the application one) in order to close excel myself. Am...
0
9656
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
10373
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
10177
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
10118
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
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
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
4074
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
2
3677
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.